当我运行这个脚本时,我刚开始使用ggplot2与R。
var<-schz.[1,]
values<-schz.[,-1]
ggplot(data=schz., aes(var, values)) + geom_boxplot()
我获得了以下错误消息:
不知道如何自动为data.frame类型的对象选择比例。默认为连续的。错误:美学必须是长度1或与数据(80):x,y相同
数据集如下:[https://drive.google.com/file/d/0B7tO-O0lx79FZERvcHJUSmxNSTQ/view?usp=sharing]
有人能告诉我怎么回事吗?我知道它是用ggplot2函数中的x和y定义的,但是我不能修复它!
发布于 2016-07-08 00:09:44
您需要将data.frame转换为长格式,例如使用dplyr::gather
schz. <- schz. %>% gather(type, value, -SITE)
ggplot(schz., aes(x=SITE, y=value, colour=type)) + geom_boxplot()
发布于 2016-07-08 00:08:39
你需要把你的数据重塑成长格式而不是宽格式。我使用来自reshape2包的熔融函数,但您也可以使用来自tidyr包的melt。
尝试:
library(reshape2)
ggplot(data=melt(schz.), aes(variable, value)) + geom_boxplot()
https://stackoverflow.com/questions/38261625
复制