繁体   English   中英

rCharts显示在RStudio Viewer中,而不显示在浏览器(Chrome)中

[英]rCharts show in RStudio Viewer, not showing in browser (Chrome)

这是我的数据

new <- structure(list(Var1 = structure(c(1L, 5L, 4L, 6L, 2L, 3L, 1L, 
5L, 4L, 6L, 2L, 3L, 1L, 5L, 4L, 6L, 2L, 3L, 1L, 5L, 4L, 6L, 2L, 
3L, 1L, 5L, 4L, 6L, 2L, 3L, 1L, 5L, 4L, 6L, 2L, 3L, 1L, 5L, 4L, 
6L, 2L, 3L, 1L, 5L, 4L, 6L, 2L, 3L, 1L, 5L, 4L, 6L, 2L, 3L, 1L, 
5L, 4L, 6L, 2L, 3L), .Label = c("Month of 2013-07", "Month of 2013-08", 
"Month of 2013-09", "Month of 2013-10", "Month of 2013-11", "Month of 2013-12"
), class = "factor"), Var2 = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 
5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 
8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 
10L, 10L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Group 1", "Group 10", 
"Group 2", "Group 3", "Group 4", "Group 5", "Group 6", "Group 7", 
"Group 8", "Group 9"), class = "factor"), value = c(1, 0.073, 
0.106, 0.056, 0.036, 0.007, 0, 1, 0.006, 0.022, 0.005, 0.038, 
0, 0.867, 1, 0.052, 0, 0.147, 0, 0.005, 0.007, 1, 0.005, 0.003, 
0, 1, 0.474, 0.017, 0, 0.039, 0.026, 0.001, 0.008, 0, 1, 0.01, 
0.004, 0, 0.074, 0.001, 0.003, 1, 0, 0.006, 1, 0.003, 0.012, 
0.011, 0, 0.911, 1, 0.352, 0, 0.27, 0, 0.349, 0.016, 0.101, 1, 
0.845)), .Names = c("Var1", "Var2", "value"), row.names = c(NA, 
-60L), class = "data.frame")

(这是图表的可重复数据)

生成图表的代码:

require(rCharts)

inteplot.7 <- rPlot(Var1 ~ Var2, color = 'value', data = new ,type = 'tile')
inteplot.7$guides("{color: {scale: {type: gradient, lower: white, upper: steelblue}}}")
inteplot.7$guides(x = list(levels = c('Group 1', 'Group 2', 'Group 3', 'Group 4', 'Group 5',
                                      'Group 6', 'Group 7', 'Group 8', 'Group 9', 'Group 10')))
inteplot.7

知道为什么它不显示在浏览器中吗?

(已编辑)我正在使用Chrome。 在IE中有效。 有什么解决方案可以使其在Chrome中运行吗? 我的降价的(edited2)选项

```{r results = 'asis', comment = NA, cache = T,echo=F,fig.height=550,out.height=550,fig.width=1000,out.width=1000,message=FALSE,warning=FALSE}
options(rcharts.mode = 'iframe', rcharts.cdn = TRUE)
    op <- options(gvis.plot.tag='chart')
    inteplot.7$show('iframesrc', cdn = T,static = FALSE)
    ```

我也经历过您描述的问题。 我发现以下解决方法,也提供了我认为更好的工作流程。

  1. 将图表从r块中另存为单独的html文件(而不是尝试“内联”显示)
  2. 使用<iframe>将图表插入html文档

我认为这是更好的工作流程,因为您可以使用有意义的名称保存所有文档的图表,并在需要时将它们插入其他文档中。 如果从现在起几个月后您的系统仍无法编译,并且期限迫在眉睫,那么您将拥有独立的html。

例:

```{r 'Figure_1_1',  results = 'asis', comment = NA, cache = FALSE, fig.height = 5, fig.width = 8} 
require(rCharts)
load("data/df_1_1.Rda") 
# round data for rChart tooltip display
df_1_1$value <- round(df_1_1$value, 2)
n <- nPlot(value ~ Year, group = 'variable', data = df_1_1, type = 'lineChart') 
n$save('figures/Figure_1_1.html', standalone = TRUE)
```
<iframe src ='figures/Figure_1_1.html', width = "860px", height = "450px"></iframe>

请注意,我是如何使用r块的fig.heightfig.width (以英寸为单位)以及html iframe的widthheight (以像素为单位)来实现高分辨率和适合网页尺寸的。 我不确定fig.heightfig.height对rChart有什么作用(如果有的话),但是如果您的文档中有其他类型的图表,例如ggplot2绘图,则可能需要在rhtml块。

如果您与fig.retina发生冲突(就像我在r块中设置out.width所做的那样),则在r块中将其设置为NULL: fig.retina = NULL

尝试这个

r1 <- rPlot(Var1 ~ Var2, color = 'value', data = new ,type = 'tile')
r1$guides("{color: {scale: {type: gradient, lower: white, upper: steelblue}}}")
r1$guides(x = list(numticks = 10))
r1

代码的麻烦是指定级别的最后一行。

看来因素级别名称中的空格是问题所在。 删除所有空格可解决此问题:

library(stringr)
levels(new$Var1) <- str_replace_all(levels(new$Var1), " ", "")
levels(new$Var2) <- str_replace_all(levels(new$Var2), " ", "")

require(rCharts)

inteplot.7 <- rPlot(Var1 ~ Var2, color = 'value', data = new ,type = 'tile')
inteplot.7$guides("{color: {scale: {type: gradient, lower: white, upper:       steelblue}}}")
inteplot.7$guides(x = list(levels = c('Group1', 'Group2', 'Group3', 'Group4', 'Group5', 'Group6', 'Group7', 'Group8', 'Group9', 'Group10')))
inteplot.7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM