计数表中的ggplot2 boxplot
问题描述:
我有一个用其他工具生成的计数表,我想用ggplot2从中获得一个箱形图.
I have a count table that I have generated with another tool, and I would like to get a boxplot from it with ggplot2.
例如,假设我有:
df1 = data.frame(nSiblings = c(0, 1, 2), count = c(10, 15, 12))
代替
df2 = data.frame(nSiblings = c(rep(0, 10), rep(1, 15), rep(2, 12)))
我知道如何从第二个数据帧生成箱形图:
I know how to produce a boxplot from the second data frame:
qplot(y=df2$nSiblings, x=1, geom = "boxplot")
我知道如何从第一个数据帧生成直方图:
I know how to produce a histogram from the first data frame:
ggplot(df1, aes(x = nSiblings, y = count)) + geom_bar(stat = "identity")
但是如何从第一个数据帧中获得箱线图?
But how can I get a boxplot from the first data frame?
答
Ggplot可以处理权重,因此您可以尝试以下操作:
Ggplot is able to work with weights, so you could try this:
ggplot(df1, aes(x=1,y=nSiblings,weights=count)) + geom_boxplot()