box plot (ggplot) help

10 views
Skip to first unread message

Zachary Pierce

unread,
Aug 25, 2016, 3:14:22 AM8/25/16
to Davis R Users' Group
Hi all,
I'm trying to create a box plot in ggplot.  I wish to plot growth scores ("above" or "below") from 3 factors at each of 2 times with a single continuous y variable (in other words, the distribution of "neo" across growth z scores at each of two times (6 and 15 wks).  .  I reshaped some data from wide to tall but can't figure out how to do what I'm saying...

ggplot(subset(g, (time==6 | time==15))) +
  geom_boxplot(aes(x=interaction(waz,haz,whz), y=neo)) +
  scale_y_continuous("NEO (nmol/L") +
  scale_x_discrete("Growth Status by Age")

...but I know that this method is plotting an interaction, and I'm not sure if that's the correct way to go about this.  Attached is my data; there are two y variables ("neo" and "mpo").  I'm terrible at R, and I'm having a rough time trying to figure out exactly how the syntax works.

Thanks much!

glong.csv

Rosemary Hartman

unread,
Aug 25, 2016, 9:27:02 AM8/25/16
to davi...@googlegroups.com
Hi Zach,

Yes, I think that does what you want (if I understand what you want). Another way to go about it would be to create a new variable out of the levels of your old variable:

glong$factors = paste(glong$whz, glong$haz, glong$waz)

ggplot(subset(glong, (time==6 | time==15))) +
  geom_boxplot(aes(x=factors, y=neo)) +

  scale_y_continuous("NEO (nmol/L") +
  scale_x_discrete("Growth Status by Age")

However, this deals with the NAs a little differently, so you'll have to decide what you want to do about them.

--
Check out our R resources at http://d-rug.github.io/
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages