计数表中的ggplot2 boxplot [英] ggplot2 boxplot from count table
本文介绍了计数表中的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()
这篇关于计数表中的ggplot2 boxplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文