【发布时间】:2022-06-22 17:30:23
【问题描述】:
我正在制作一个图表,显示随着时间的推移几种动物的家园范围大小。图例自动填充到图的右侧,我可以使用+ theme(legend.position= "position") 成功地将它移动到图的上方、下方或左侧,但是当我尝试使用+ theme(legend.position= c(1, 250)) 在图中移动图例时,它消失了.
我的数据由列“id”(字符向量)、“wtd_area”(数字)和“study_year”(数字)组成。
data %>%
ggplot(aes(x= study_year, y= wtd_area, color= id, shape= id)) +
theme_js() +
geom_point(size= 3) + geom_line(aes(group=id), size= 1) +
ylim(0,160) + scale_color_manual(values= palette) +
labs(x= NULL, y= NULL, color= "Animal ID", shape= "Animal ID") +
theme(legend.position= c(1,150))
我有:
1.) 确认自定义主题 theme_js() 不会因切换到通用主题而受到干扰。
2.) 将aes(color= id, shape= id) 和aes(color= id) 分别添加到geom_point() 和geom_line()。
3.) 将show.legend= TRUE 添加到geom_point() 和geom_line()。
4.) 将aesthetics= "color" 添加到scale_color_manual()。
palette 是一个包含颜色十六进制代码的字符向量。
【问题讨论】: