rcharts nvd3 linechart with categorical x axis

妖精的绣舞 提交于 2019-12-14 02:19:09

问题


How can I a draw a linechart with rcharts using nvd3 and a categorical xaxis? What I'm trying to do would look with ggplot2 like this:

library(ggplot2)
dat <- data.frame(expand.grid(group = letters[1:3], x = letters[4:6]), y = rnorm(9))
ggplot(dat, aes(x = x, y = y, group = group, color = group)) + geom_line()

I tried:

library(rCharts)
nPlot(y ~ x, group = 'group', data = dat, type = 'lineChart')

I know that I could change x to a numeric variable, but then the xaxis labels would not be correctly written.


回答1:


is this what you are after?

foo <- hPlot(x = "x", y = "y", groups = "group", data = dat, type = "line")
foo


来源:https://stackoverflow.com/questions/25481853/rcharts-nvd3-linechart-with-categorical-x-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!