about boxplots in R

1,338 views
Skip to first unread message

lily li

unread,
Dec 26, 2016, 11:23:13 PM12/26/16
to ggp...@googlegroups.com
Hi ggplot users,

I'm trying to plot boxplots, but have some problems. The data frame is like this:
df
year    month    flow
1990      1          10
1990      2          13
1990      3          20
...
2010     12         14

box1 = ggplot(subset(df, year %in% c(1995:2010), aes(x=month, y=flow)+
     geom_boxplot()+ xlab('Months')+ ylab('Flow (mm/month))
print(box1)

But then it shows the error:
Warning message:
Continuous x aesthetic -- did you forget aes(group=...)? 

I really can't check out any problem. Thanks for your help.

eipi10

unread,
Dec 26, 2016, 11:48:59 PM12/26/16
to ggplot2
month is a number, so ggplot treats it as a continuous variable. Change to x=factor(month) and ggplot will then treat each month as a categorical variable.

lily li

unread,
Dec 26, 2016, 11:57:18 PM12/26/16
to eipi10, ggplot2
Thanks, it solved the problem. I didn't know where to check out.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hadley Wickham

unread,
Dec 30, 2016, 5:01:10 PM12/30/16
to eipi10, ggplot2
The error message also gives a hint ;)

ggplot(subset(df, year %in% c(1995:2010), aes(month, flow) +
geom_boxplot(aes(group = month)) +
xlab('Months') +
ylab('Flow (mm/month))

Hadley
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://hadley.nz
Reply all
Reply to author
Forward
0 new messages