#Your sample data...
df= data.frame(id = 1:10,
var1 = rnorm(10),
var2 = rnorm(10),
var3= rnorm(10),
factor.col= LETTERS[1:10]
)
# Use the reshape2 package to merge the columns by id and factor.col
library(reshape2)
df_long <- melt(df, id=c("id","factor.col"))
# And now plot the boxplots
library(ggplot2)
ggplot(df_long,aes(x=factor.col,y=value)) + geom_boxplot()
2 回答
以下工作“在同一图中绘制多个数字列的箱线图,并按箱子图分组”:
数据:
以下也可以使用:
当您使用
ggplot2
时,您的数据布局需要与基本图形的布局有所不同