Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

r - geom_boxplot with precomputed values

In the past, I have been able to create boxplots using ggplot2 by providing the lower whisker, lower quantile, median, upper quantile, and upper whisker along with x-axis labels. For example:

DF <- data.frame(x=c("A","B"), min=c(1,2), low=c(2,3), mid=c(3,4), top=c(4,5), max=c(5,6))
ggplot(DF, aes(x=x, y=c(min,low,mid,top,max))) +
geom_boxplot()

would make a boxplot for two sets of data (A & B). This no longer works for me. I get the following error:

Error: Aesthetics must either be length one, or the same length as the dataProblems:x

Does anyone know if something has been changed in ggplot2?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works using ggplot2 version 0.9.1 (and R 2.15.0)

library(ggplot2)

DF <- data.frame(x=c("A","B"), min=c(1,2), low=c(2,3), mid=c(3,4), top=c(4,5), max=c(5,6))

ggplot(DF, aes(x=x, ymin = min, lower = low, middle = mid, upper = top, ymax = max)) +
  geom_boxplot(stat = "identity")

enter image description here

See the "Using precomputed statistics" example here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...