我正在探索 reCharts。我在向 Y 轴和标题添加标签时陷入困境。我是 rCharts 新手。
这是我的示例代码
require(rCharts)
n2 <- nPlot(Hours ~ Month, group = "Task", data = cars, type = "multiBarChart",
height = 900, width = 1110)
n2$xAxis(axisLabel = 'Year and Month')
n2
请帮忙。
答案补充标题示例 2013-12-05
我不记得为什么nvd3
with rCharts
这样做,但我们在这个中发现了这一点issue https://github.com/ramnathv/rCharts/issues/102。该问题中建议的方法有效,但使用margin
可能是更稳健的方法。我已经将这两种方式放在一起做了一个简单的例子。让我知道这是如何运作的。
require(rCharts)
df <- data.frame(x=1:20,y=runif(n=20))
n1 <- nPlot(
y~x,
data=df,
type="multiBarChart"
)
n1$yAxis( axisLabel = "Randomness" )
#nvd3 draws the label but falls outside the bounds
#so two ways to fix
#best way I believe is to set the margin to allow room
#nvd3 draws at -63, so something bigger than 63
n1$chart(margin = list(left = 100))
n1
#second way as discussed here
#https://github.com/ramnathv/rCharts/issues/102
n1$yAxis( axisLabel = "Randomness", width = 40 )
n1
现在让我们添加一个标题
有几种方法可以实现这一目标。我目前更喜欢使用脚本模板rCharts
。这里有两个例子。一个<h3>
元素被插入到rCharts
分区这两个模板位于这个仓库 https://github.com/timelyportfolio/rcharts_nvd3_templates如果你想看看它们是如何工作的。
#for a local template something like this
#n1$templates$script <- "./chartWithTitle.html"
n1$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle.html"
n1$set(title = "rCharts + nvd3 Power")
n1
#using some css style from http://tympanus.net/codrops/2012/11/02/heading-set-styling-with-css/
#put in a different template
n1$templates$script <- "http://timelyportfolio.github.io/rCharts_nvd3_templates/chartWithTitle_styled.html"
n1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)