0
votes

I'm newbie at using ggplot2 with R. When I run this script

var<-schz.[1,]
values<-schz.[,-1]
ggplot(data=schz., aes(var, values)) + geom_boxplot()

I obtained this error message:

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

The dataset is the following: [https://drive.google.com/file/d/0B7tO-O0lx79FZERvcHJUSmxNSTQ/view?usp=sharing]

Someone can tell me what's wrong? I understand it's something with the definition of x and y in the ggplot2 function, but I can't fix it!

2

2 Answers

1
votes

You need to change your data.frame into a long format e.g. with dplyr::gather

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

enter image description here

0
votes

You need to reshape your data into long format instead of wide. I use the melt function from the reshape2 package, but you can also use gather from the tidyr package.

Try:

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