我正在尝试使用 ggplot 添加图例标题,但通常的 labs(fill = "XXX") 函数不起作用。有谁知道为什么吗?
这是迄今为止的代码:
img_summary %>%
ggplot(aes(x = fantasy_group, y = mean_think, fill = fantasy_type)) +
geom_col(colour = "black", width = .7, position = position_dodge(.7)) +
geom_errorbar(aes(ymin = mean_think - 1*se_think,
ymax = mean_think + 1*se_think),
position = position_dodge(.7), width = .25) +
scale_x_discrete(labels = c("Dominant", "Intimacy", "Promiscuous", "Submissive")) +
scale_y_continuous(breaks = seq(0,100, by = 10), limits = c(0,100), expand = c(0,0)) +
scale_fill_manual(values = c('#3B3B3B', '#656465', '#A0A0A0', '#D3D3D3'),
labels = c("Being dominant", "Being loved", "Impersonal sex", "Being submissive")) +
labs(x = "Fantasy Group", y = "Mean Time Thinking (0-100)", title = "Figure 1: Mean percentage of time thinking of each fantasy type by fantasy group", fill = "Fantasy Type") +
theme_apa()
我尝试过
fill = "Fantasy Type"
和 colour = "Fantasy Type"
但没有出现图例标题。
我浏览了一大堆其他问题页面,似乎找不到正确的解决方案。
theme_apa
中的 jtools
包有一个参数,默认值为 legend.use.title = FALSE
。在代码注释中(https://rdrr.io/cran/jtools/src/R/theme_apa.R)它指出:
关于 APA 风格的人物需要记住一些事项:
- 主要标题应写在文字处理器或排字机中,而不是写在绘图图像本身上。
- 在某些情况下,用户可以放弃图例,转而在标题中描述图形(也用文字处理器/排字机编写)。
- 图例通常嵌入在图形的坐标平面上,而不是紧挨着它,就像默认的那样