我正在尝试制作一张快速图表以显示几组的均值。我的y axis
的范围是-2
至+2
。我的两个组的平均值为零,因此图中没有任何显示。有没有一种好的方法将两个均值表示为零?零是一个有意义的数字。我在想像一个粉红色的小酒吧或一个蓝色的酒吧。
有什么建议吗?抱歉,代码混乱!
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, 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)
我知道这不是我的职权,但我可以允许我对您的阴谋发表一些评论吗?
coord_...()
调用中执行此操作以下是我根据上述评论如何绘制的建议:
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
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9WVmh4UndQLnBuZyJ9” alt =“”>
由reprex package(v0.3.0)在2020-03-24创建