Support

Support Options

  • Knowledge Base

    Find information on common questions and issues.

  • Support Messages

    Check on the status of your correspondences with members of the QUBES team.

Contact Us

Questions and Answers

0 Dislike

David Leaf

Making boxplots with ggplot2

Hi all,

I'd like to be able use R (in which I am a rank novice) to plot out multivariate datasets from Behavior Space simulations in R (in which I am also a rank novice).   In these Flocking simulations, there are 10 runs at a 5 different population sizes and 10 different vision settings.  After 500 ticks, the standard deviation of heading angle is calculated.   In R, I can make boxplots of the Standard Deviation versus population for each of the population sizes in one graph very simply.  (> boxplot(sd~pop, data=flockingdsl)).   This approach is using the standard graphing format in R, but what I would like to do is use the higher-level ggplot2 which, in principle, can make more aesthetic graphs relatively easy.  

When I use the ggplot2 or qplot to make a boxplot of the same dataset, all of the population data is grouped together to make one big boxplot instead of 5 different boxplots.  (> qplot(flockingdsl$sd, flockingdsl$pop, geom="boxplot").  I also receive a message from R: "Warning message: Continuous x aesthetic -- did you forget aes(group=...)?".

When I take the same dataframe to make a scatterplot with ggplot2, it works perfectly fine.  (ggplot(flockingdsl, aes(x=pop, y=sd, colour=vis)) + geom_point(size=5).  

I'd really like to take advantage of ggplot2, but there seems to be some issue about how the data is encoded or organized such that ggplot2 can't read it appropriately.  Thanks in advance for any insights from the R folks.

david leaf

 

Report abuse

1 Responses

  1. 0 Dislike

    David Leaf

    A colleague kindly provided an easy workaround, so that the values in population were not read as continuous.  It works!

    > ggplot(flockingdsl, aes(x = factor(pop), y = sd)) +     geom_boxplot()

    Reply Report abuse

    Please login to answer the question.

Dashboard

Close