2012-05-17 49 views
8

過去,通過提供更低的晶須,更低的分位數,中位數,上分位數和上晶須以及x軸標籤,我能夠使用ggplot2創建箱形圖。例如:帶有預先計算值的geom_boxplot

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() 

會使的箱線圖用於兩組數據(A & B)。這不再適用於我。我收到以下錯誤:

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

有沒有人知道ggplot2中有什麼改變?

+1

因爲它可能是之間的變化ggplot2的版本,你使用什麼版本('sessionInfo()')。我在R 2.15.0中使用了ggplot2_0.9.0,它適用於我,所以我想它必須與R或ggplot2版本有關。 –

回答

11

這個工程使用GGPLOT2版本0.9.1(和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

請參閱 「使用預先計算的統計數據」 例如here