barplot with groups - need to drop levels with value = 0

32 views
Skip to first unread message

j0hnCathey

unread,
Jul 28, 2017, 4:59:03 AM7/28/17
to ggplot2
I'm trying to do a bar plot of systolic (S) and diastolic (D) blood pressure values for three groups (1,2,3). I converted the dataset to long form so I have one variable type of measurement (levels: S1, D1, S2, D2,  S3, D3) and variable of the values for each. I added a column for the groups (1,2,3) so I could get a separate bar for each group (fill=group in the aes). That produced a graph with all the bars equally spaced, so I added another variable S and D,  with S for all S1, S2, S3 and same for D so I could use facet_wrap to get better separation of the S and D bars (that seems to be the only way). But now the D facet leaves a spaces for the S1, S2, S3 with value = 0, and same in reverse for the S facet. If you still follow all this, how can I get rid of those levels with value=0 in the facets?

Roman Luštrik

unread,
Jul 28, 2017, 5:14:48 AM7/28/17
to j0hnCathey, ggplot2

On Fri, Jul 28, 2017 at 10:59 AM, j0hnCathey <jtca...@gmail.com> wrote:
I'm trying to do a bar plot of systolic (S) and diastolic (D) blood pressure values for three groups (1,2,3). I converted the dataset to long form so I have one variable type of measurement (levels: S1, D1, S2, D2,  S3, D3) and variable of the values for each. I added a column for the groups (1,2,3) so I could get a separate bar for each group (fill=group in the aes). That produced a graph with all the bars equally spaced, so I added another variable S and D,  with S for all S1, S2, S3 and same for D so I could use facet_wrap to get better separation of the S and D bars (that seems to be the only way). But now the D facet leaves a spaces for the S1, S2, S3 with value = 0, and same in reverse for the S facet. If you still follow all this, how can I get rid of those levels with value=0 in the facets?

--
--
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.



--
In God we trust, all others bring data.

j0hnCathey

unread,
Jul 28, 2017, 5:40:29 AM7/28/17
to ggplot2, jtca...@gmail.com
I just solved it sort of accidentally. Adding the argument scale="free_x" in facet_wrap produced what I needed. I'll figure out why later. Thanks


On Friday, July 28, 2017 at 4:14:48 PM UTC+7, Roman Luštrik wrote:
On Fri, Jul 28, 2017 at 10:59 AM, j0hnCathey <jtca...@gmail.com> wrote:
I'm trying to do a bar plot of systolic (S) and diastolic (D) blood pressure values for three groups (1,2,3). I converted the dataset to long form so I have one variable type of measurement (levels: S1, D1, S2, D2,  S3, D3) and variable of the values for each. I added a column for the groups (1,2,3) so I could get a separate bar for each group (fill=group in the aes). That produced a graph with all the bars equally spaced, so I added another variable S and D,  with S for all S1, S2, S3 and same for D so I could use facet_wrap to get better separation of the S and D bars (that seems to be the only way). But now the D facet leaves a spaces for the S1, S2, S3 with value = 0, and same in reverse for the S facet. If you still follow all this, how can I get rid of those levels with value=0 in the facets?

--
--
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.
Reply all
Reply to author
Forward
0 new messages