I am trying to make a quick graph to show the means of a few groups. My y axis
ranges from -2
to +2
. Two of my groups have a mean of zero, therefore nothing shows up on the graph. Is there a good way to depict the two means at zero? Zero is a meaningful number. I was thinking like a small pink bar or blue bar.
Any suggestions? Sorry in advance for the messy code!
conseq_summary_table=structure(list(age_group = c("4", "4", "5", "5", "adult", "adult"),
condition_motive = c("bad", "good", "bad", "good", "bad", "good"),
group_conseq_mean = c(0, 0.192307692307, 0.133333333333,
-0.0333333333333, -0.710526315789, 0),
conseq_sd = c(0.577350269189, 0.722797272709,
0.549891764241,0.611399643285, 0.450795268685, 0)),
row.names = c(NA, -6L),
class = c("grouped_df", "tbl_df", "tbl", "data.frame"),
groups = structure(list(age_group = c("4", "5", "adult"),
.rows = list(1:2, 3:4, 5:6)), row.names = c(NA, -3L),
class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
Here is my current code:
ggplot(conseq_summary_table, aes(age_group, conseq_mean )) +
geom_bar(aes(fill = condition_motive), stat = "identity", position = "dodge",
alpha = .7) +
labs(title = "Summary of conseq", x = "Age Group", y = "Average conseq" ) +
theme_minimal() +
scale_y_continuous(expand = c(0,0),
limits = c(-2,2)) +
geom_hline(yintercept=0)
I know it's not really my remit, but may I allow myself some comments on your plot?
coord_...()
callsBelow a suggestion how I would plot this based on the above comments:
library(ggplot2)
conseq_summary_table <- structure(list(age_group = c("4", "4", "5", "5", "adult", "adult"), condition_motive = c("bad", "good", "bad", "good", "bad", "good"), group_conseq_mean = c(0, 0.192307692307, 0.133333333333, -0.0333333333333, -0.710526315789, 0), conseq_sd = c(0.577350269189, 0.722797272709, 0.549891764241,0.611399643285, 0.450795268685, 0)), row.names = c(NA, -6L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), groups = structure(list(age_group = c("4", "5", "adult"), .rows = list(1:2, 3:4, 5:6)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
ggplot(conseq_summary_table, aes(age_group, group_conseq_mean )) +
geom_hline(yintercept=0) +
geom_pointrange(aes(ymin= group_conseq_mean - conseq_sd,
ymax = group_conseq_mean + conseq_sd, color = condition_motive),
position = position_dodge(width = 1)) +
scale_color_brewer(palette = 'Set1') +
scale_y_continuous() +
facet_wrap(~ age_group, scales = 'free_x') # maybe try facetting by condition_motive instead
Created on 2020-03-24 by the reprex package (v0.3.0)