【发布时间】:2015-03-09 16:15:18
【问题描述】:
我使用rCharts 包创建了一个nvd3 类型图。我将它保存在独立的html 中,并将其导入到带有<iframe src = 'Figure.html'> 的rmarkdown 文档中。
我通过“检查元素”功能查看了 Chrome 和 Firefox 中的 html 源代码,发现对 css 的以下编辑:
.nvd3.nv-line .nvd3.nv-scatter .nv-groups .nv-point {
stroke-width: 10px;
fill-opacity: 1;
stroke-opacity: 1;
}
给予:
这是我想要得到的效果。但是,如果我将上面的代码插入css,它就不会被“拾取”。选择了其他样式,因此正在读取 css,但上面的内容似乎被丢弃了。有什么想法吗?
html 图在这里:https://gist.github.com/anonymous/b187e77d795e5bf96f51
编辑感谢 jbaums 和 sal niro 的提示,破解了这个。这是将带有“lineChart”的rChartsnPlot 转换为“lineChart”和“scatterChart”的组合的工作流程。这是您的rmarkdown 代码的相关部分:
```{r 'Figure'}
require(rCharts)
load("data/df.Rda")
# round data for rChart tooltip display
df$value <- round(df$value, 2)
n <- nPlot(value ~ Year, group = 'variable', data = df, type = 'lineChart')
n$yAxis(axisLabel = 'Labor and capital income (% national income)')
n$chart(margin = list(left = 100)) # margin makes room for label
n$yAxis(tickFormat = "#! function(d) {return Math.round(d*100*100)/100 + '%'} !#")
n$xAxis(axisLabel = 'Year')
n$chart(useInteractiveGuideline=TRUE)
n$chart(color = colorPalette)
n$addParams(height = 500, width = 800)
n$setTemplate(afterScript = '<style>
.nv-point {
stroke-opacity: 1!important;
stroke-width: 6px!important;
fill-opacity: 1!important;
}
</style>'
)
n$save('figures/Figure.html', standalone = TRUE)
```
【问题讨论】:
-
您可能需要通过 JS 通过
append().attr()函数来执行此操作 -
@salniro,哦,我不知道这涉及到什么!任何提示表示赞赏,谢谢。
-
我在 D3 中遇到了同样的问题。在JS中添加
svg元素时需要做的希望你能找到! -
谢谢,当我检查代码时,我可以看到 svg 元素,所以我会看看它是否能帮到我。另外,我正在读这个:stackoverflow.com/questions/710275/…,但我一点也不聪明。
标签: html css r r-markdown