2016-07-08 54 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()