facet

8 views
Skip to first unread message

J H

unread,
Mar 4, 2014, 11:23:38 PM3/4/14
to ggp...@googlegroups.com
I am using facet to plot box plots.  the facets are separated by 2 states, however, one of the x axis categories does not apply for one of the states. Since there is no data for that category.  I do not want to show it at all in the plot.  Is there a way to limit that?  here is the code and data.  Basically I don't want category "B" to be show for state NY.

Thanks,



CODE
ggplot(table, aes(x=Category, y=Value, fill=Category)) + geom_boxplot()+ facet_grid(.~ State)


DATA
State Value Category
CA 323 A
CA 23 A
CA 42 A
CA 4 A
CA 2 B
CA 42 B
CA 342 B
CA 4 B
CA 23 C
CA 42 C
CA 2 C
NY 3 A
NY 2 A
NY 4 A
NY 2 A
NY 342 A
NY 3 A
NY 23 C
NY 42 C
NY 3 C
NY 2 C
NY 32 C
NY 3 C

J H

unread,
Mar 4, 2014, 11:24:30 PM3/4/14
to ggp...@googlegroups.com
Here is the plot
Screen Shot 2014-03-04 at 8.24.18 PM.jpg

Doug Mitarotonda

unread,
Mar 4, 2014, 11:40:31 PM3/4/14
to J H, ggp...@googlegroups.com
See ?facet_grid. There is a `scales` argument. You want "free_x" in this case.

--
--
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/groups/opt_out.
<Screen Shot 2014-03-04 at 8.24.18 PM.jpg>

Doug Mitarotonda

unread,
Mar 5, 2014, 10:50:30 AM3/5/14
to J H, ggplot2
Read the next argument to `facet_grid`, `spaces`. Also, be sure to include the group when you respond to emails. 


On Mar 5, 2014, at 7:25 AM, J H <renalcl...@gmail.com> wrote:

Doug, Thanks.  However one other question.  While this does the trick it makes the box plot much larger in comparison to the other boxplots.  Is there a way to force the width of the boxplot to be the same?  Thanks. J

J H

unread,
Mar 5, 2014, 11:09:37 AM3/5/14
to Doug Mitarotonda, ggplot2
Ok thanks Doug. Works fine now. Thanks for all the help.
Reply all
Reply to author
Forward
0 new messages