r - rCharts绘制了一些数据帧而不是其他数据帧

时间:2016-02-11 06:28:42

标签: r rcharts

使用library(rCharts)和完全相同的绘图代码,为什么会绘制其中一些data.frame,有些则不会?

## Install:
# library(devtools); install_github('ramnathv/rCharts'); library(rCharts)

## Successful plot
set.seed(1)
df <- data.frame(var1 = letters,
                                 var2 = rnorm(26, 0, 1))

rPlot(x = list(var = "var1", sort = "var2"), y = "var2", data = df, color = "var1", type = "bar")
## No Plot
set.seed(1)
df <- data.frame(var1 = 1:26,
                                 var2 = rnorm(26, 0, 1))

rPlot(x = list(var = "var1", sort = "var2"), y = "var2", data = df, color = "var1", type = "bar")
## No Plot
set.seed(1)
df <- data.frame(var1 = 1:26,
                                 var2 = rnorm(26, 0, 1))
## convert to char
df$var1 <- as.character(df$var1)
rPlot(x = list(var = "var1", sort = "var2"), y = "var2", data = df, color = "var1", type = "bar")
## Successful plot
set.seed(1)
df <- data.frame(var1 = 1:26,
                                 var2 = rnorm(26, 0, 1))
## paste a string onto var1
df$var1 <- paste0(df$var1, "_")

rPlot(x = list(var = "var1", sort = "var2"), y = "var2", data = df, color = "var1", type = "bar")

会话信息

enter image description here

0 个答案:

没有答案