带有 rCharts 的 Highcharts 3D
Highcharts 3D with rCharts
带有 rCharts 的 Highcharts 3D
rCharts可以和Highcharts的3D模块一起使用吗?以下是 Highcharts 3D 的示例:
错误
下面我的示例代码出现的错误是:
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : ‘zAxis’ is not a valid field or method name for reference class “Highcharts”
示例代码
这是我使用的示例代码:
library(rCharts)
# Based on example from: http://jsfiddle.net/highcharts/V37Vv/light/
plotData <- data.frame(x = c(1,1,1,2,2,4,4,7,7,8),
y = c(1,1,1,3,6,5,2,1,1,1),
z = c(1,2,5,2,4,7,8,3,5,5),
category=rep(c("A", "B"), 5), stringsAsFactors=FALSE)
xLabel <- "X"
yLabel <- "Y"
zLabel <- "Z"
title <- "Title"
if (is.null(rownames(plotData))){
rownames(plotData) <- as.character(1:nrow(plotData))
}
# HighCharts point name
plotData$name <- rownames(plotData)
# Scatter plot
h1 <- rCharts::Highcharts$new()
h1$setLib("libraries/widgets/highcharts")
h1$chart(renderTo="container",
margin=c(150, 75, 75, 75),
type='scatter',
options3d=list(enabled=TRUE,
alpha=20,
beta=30,
depth=200))
h1$title(text=title)
h1$xAxis(title=list(enabled=TRUE, text=xLabel))
h1$yAxis(title=list(enabled=TRUE, text=yLabel))
h1$zAxis(title=list(enabled=TRUE, text=zLabel))
# Divide the dataset, split by category and put into list() format
# From: http://rcharts.io/viewer/?5735146#.VF6NS4W1Fy4
series <- lapply(split(plotData, plotData$category), function(x) {
res <- lapply(split(x, rownames(x)), as.list)
names(res) <- NULL
return(res)
})
invisible(sapply(series, function(x) {
h1$series(data=x, type="scatter", name=x[[1]]$category)
}
))
h1$legend(enabled=FALSE)
# Force circle markers and change size
h1$plotOptions(scatter=list(marker=list(symbol='circle', radius=6)))
h1$tooltip(formatter = "#! function() { return this.point.name + ', ' +
this.series.name + ', ' + this.x + ', ' + this.y; } !#")
# Enable exporting
h1$exporting(enabled=TRUE)
# Set name
h1$set(dom=xLabel)
# Print chart
print(h1)
#h1$show("inline")
Highcharts/rCharts 文件夹:libraries/widgets/highcharts
此文件夹包含 config.yml:
config.yml
highcharts:
jshead:
- js/jquery-1.7.min.js
- js/highcharts.js
- js/highcharts-more.js
- js/exporting.js
- js/highcharts-3d.js
cdn:
jshead:
- "http://code.jquery.com/jquery-1.7.min.js"
- "http://code.highcharts.com/highcharts.js"
- "http://code.highcharts.com/highcharts-more.js"
- "http://code.highcharts.com/highcharts-3d.js"
- "http://code.highcharts.com/modules/exporting.js"
js/文件夹
js/ 文件夹中有 config.yml
中引用的文件
布局/文件夹
布局/文件夹有 chart.html
chart.html
<script type='text/javascript'>
(function($){
$(function () {
var chart = new Highcharts.Chart({{{ chartParams }}});
});
})(jQuery);
</script>
我不认为 3D 图表在 rCharts 中可用,因此不存在 z 轴上的错误。
相反,您必须使用包 rthreejs based on Ramnathv's htmlwidget 包,它也适用于 Rmarkdown 和 Shiny。
devtools::install_github("ramnathv/htmlwidgets")
devtools::install_github("bwlewis/rthreejs")
libs <- c("htmlwidgets", "threejs")
lapply(libs, library, character.only=TRUE)
Example 在 htmlwidget galery
现在有另一个 R 的 highcharts 包装器。包括 3d 模块。此处示例:http://jkunst.com/highcharter/highcharts-api.html.
代码
data(citytemp)
hc <- highchart() %>%
hc_xAxis(categories = citytemp$month) %>%
hc_add_series(name = "Tokyo", data = citytemp$tokyo) %>%
hc_add_series(name = "London", data = citytemp$london) %>%
hc_add_series(name = "Other city",
data = (citytemp$tokyo + citytemp$london)/2) %>%
hc_chart(type = "column",
options3d = list(enabled = TRUE, beta = 15, alpha = 15))
hc
带有 rCharts 的 Highcharts 3D
rCharts可以和Highcharts的3D模块一起使用吗?以下是 Highcharts 3D 的示例:
错误
下面我的示例代码出现的错误是:
Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : ‘zAxis’ is not a valid field or method name for reference class “Highcharts”
示例代码
这是我使用的示例代码:
library(rCharts)
# Based on example from: http://jsfiddle.net/highcharts/V37Vv/light/
plotData <- data.frame(x = c(1,1,1,2,2,4,4,7,7,8),
y = c(1,1,1,3,6,5,2,1,1,1),
z = c(1,2,5,2,4,7,8,3,5,5),
category=rep(c("A", "B"), 5), stringsAsFactors=FALSE)
xLabel <- "X"
yLabel <- "Y"
zLabel <- "Z"
title <- "Title"
if (is.null(rownames(plotData))){
rownames(plotData) <- as.character(1:nrow(plotData))
}
# HighCharts point name
plotData$name <- rownames(plotData)
# Scatter plot
h1 <- rCharts::Highcharts$new()
h1$setLib("libraries/widgets/highcharts")
h1$chart(renderTo="container",
margin=c(150, 75, 75, 75),
type='scatter',
options3d=list(enabled=TRUE,
alpha=20,
beta=30,
depth=200))
h1$title(text=title)
h1$xAxis(title=list(enabled=TRUE, text=xLabel))
h1$yAxis(title=list(enabled=TRUE, text=yLabel))
h1$zAxis(title=list(enabled=TRUE, text=zLabel))
# Divide the dataset, split by category and put into list() format
# From: http://rcharts.io/viewer/?5735146#.VF6NS4W1Fy4
series <- lapply(split(plotData, plotData$category), function(x) {
res <- lapply(split(x, rownames(x)), as.list)
names(res) <- NULL
return(res)
})
invisible(sapply(series, function(x) {
h1$series(data=x, type="scatter", name=x[[1]]$category)
}
))
h1$legend(enabled=FALSE)
# Force circle markers and change size
h1$plotOptions(scatter=list(marker=list(symbol='circle', radius=6)))
h1$tooltip(formatter = "#! function() { return this.point.name + ', ' +
this.series.name + ', ' + this.x + ', ' + this.y; } !#")
# Enable exporting
h1$exporting(enabled=TRUE)
# Set name
h1$set(dom=xLabel)
# Print chart
print(h1)
#h1$show("inline")
Highcharts/rCharts 文件夹:libraries/widgets/highcharts
此文件夹包含 config.yml:
config.yml
highcharts:
jshead:
- js/jquery-1.7.min.js
- js/highcharts.js
- js/highcharts-more.js
- js/exporting.js
- js/highcharts-3d.js
cdn:
jshead:
- "http://code.jquery.com/jquery-1.7.min.js"
- "http://code.highcharts.com/highcharts.js"
- "http://code.highcharts.com/highcharts-more.js"
- "http://code.highcharts.com/highcharts-3d.js"
- "http://code.highcharts.com/modules/exporting.js"
js/文件夹
js/ 文件夹中有 config.yml
中引用的文件布局/文件夹
布局/文件夹有 chart.html
chart.html
<script type='text/javascript'>
(function($){
$(function () {
var chart = new Highcharts.Chart({{{ chartParams }}});
});
})(jQuery);
</script>
我不认为 3D 图表在 rCharts 中可用,因此不存在 z 轴上的错误。
相反,您必须使用包 rthreejs based on Ramnathv's htmlwidget 包,它也适用于 Rmarkdown 和 Shiny。
devtools::install_github("ramnathv/htmlwidgets")
devtools::install_github("bwlewis/rthreejs")
libs <- c("htmlwidgets", "threejs")
lapply(libs, library, character.only=TRUE)
Example 在 htmlwidget galery
现在有另一个 R 的 highcharts 包装器。包括 3d 模块。此处示例:http://jkunst.com/highcharter/highcharts-api.html.
代码
data(citytemp)
hc <- highchart() %>%
hc_xAxis(categories = citytemp$month) %>%
hc_add_series(name = "Tokyo", data = citytemp$tokyo) %>%
hc_add_series(name = "London", data = citytemp$london) %>%
hc_add_series(name = "Other city",
data = (citytemp$tokyo + citytemp$london)/2) %>%
hc_chart(type = "column",
options3d = list(enabled = TRUE, beta = 15, alpha = 15))
hc