【发布时间】:2021-11-25 08:34:32
【问题描述】:
我正在尝试将黑色实线识别为“中位数”,将红色虚线识别为“平均值”。
但是,即使我包含show.legend = TRUE 和legend.position = "right",图例也不会显示在图表上。我将在我的箱线图下方添加一张图片,因为它目前没有图例。
图片说明:
我的代码如下:
box %>%
pivot_longer(cols = c(Total, EX, MD, CI, EI)) %>%
ggplot(aes(x = name, y = value)) +
geom_boxplot(fill="gray", show.legend = TRUE) +
labs(x = "Burnout Dimension", y = "Likert Response Count") +
stat_summary(fun.y = mean, geom = "errorbar", aes(ymax = ..y.., ymin = ..y..),
width = .75, linetype = "dashed", color="red") +
scale_colour_manual("Values", values=c("blue", "red")) +
theme_minimal() +
theme(text = element_text(family="Times New Roman",
color="#595959",
size=14),
legend.position = "right",
panel.grid.major.y = element_line(c(0,25,50,75,100),
color="#D9D9D9",
size=0.2),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank())
【问题讨论】: