0

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 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, I'll do that!
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.