2016-07-08 52 views
0

當我在使用與GGPLOT2 R.林新手當運行該腳本錯誤製造的箱線圖與GGPLOT2

​​

我獲得此錯誤消息:

Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous. Error: Aesthetics must be either length 1 or the same as the data (80): x, y

該數據集爲以下: [https://drive.google.com/file/d/0B7tO-O0lx79FZERvcHJUSmxNSTQ/view?usp=sharing]

有人可以告訴我什麼是錯?我知道這是ggplot2函數中x和y的定義,但我無法修復它!

回答

0

你需要改變你的data.frame成一個長格式如與dplyr::gather

schz. <- schz. %>% gather(type, value, -SITE) 
ggplot(schz., aes(x=SITE, y=value, colour=type)) + geom_boxplot() 

enter image description here

+0

非常感謝,我會的! –

0

您需要將數據重塑爲長格式而不是寬格式。我使用reshape2軟件包中的熔化函數,但您也可以使用tidyr軟件包中的聚集函數。

嘗試:

library(reshape2) 
ggplot(data=melt(schz.), aes(variable, value)) + geom_boxplot()