问题
I have a count table that I have generated with another tool, and I would like to get a boxplot from it with ggplot2.
For instance, suppose that I have:
df1 = data.frame(nSiblings = c(0, 1, 2), count = c(10, 15, 12))
instead of
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?
回答1:
Ggplot is able to work with weights, so you could try this:
ggplot(df1, aes(x=1,y=nSiblings,weights=count)) + geom_boxplot()
来源:https://stackoverflow.com/questions/34204175/ggplot2-boxplot-from-count-table