我在理解如何使用包rPlot
中的函数自定义图表时遇到了一些麻烦rCharts
。说我有以下代码
#Install rCharts if you do not already have it
#This will require devtools, which can be downloaded from CRAN
require(devtools)
install_github('rCharts', 'ramnathv')
#simulate some random normal data
x <- rnorm(100, 50, 5)
y <- rnorm(100, 30, 2)
#store in a data frame for easy retrieval
demoData <- data.frame(x,y)
#generate the rPlot Object
demoChart <- rPlot(y~x, data = demoData, type = 'point')
#return the object // view the plot
demoChart
这将生成一个图,这很好,但是我将如何沿 y 轴添加水平线?例如,如果我想画一条代表平均 y 值的绿线,然后画一条代表平均值 +/- 3 个标准偏差的红线?如果有人知道一些文档并可以指出我,那就太好了。但是,我能找到的唯一文档是 polychart.js ( https://github.com/Polychart/polychart2 ),我不太确定如何将其应用于rCharts
rPlot
R 中的函数。
我已经做了一些挖掘,我觉得答案将与添加/修改对象layers
parameter
内部有关rPlot
。
#look at the slots in this object
demoChart$params$layers
#doing this will return the following output (which will be different for
#everybody because I didn't set a seed). Also, I removed rows 6:100 of the data.
demoChart$params$layers
[[1]]
[[1]]$x
[1] "x"
[[1]]$y
[1] "y"
[[1]]$data
x y
1 49.66518 32.75435
2 42.59585 30.54304
3 53.40338 31.71185
4 58.01907 28.98096
5 55.67123 29.15870
[[1]]$facet
NULL
[[1]]$type
[1] "point"
如果我解决了这个问题,我会发布一个解决方案,但在此期间我将不胜感激任何帮助/建议!我没有太多在 R 中玩对象的经验。我觉得这应该有一些相似之处ggplot2
,我也没有太多经验。
感谢您的任何建议!