[英]Legend disappears when moved inside of ggplot
我正在制作一個圖,顯示隨着時間的推移幾種動物的家庭范圍大小。 圖例自動填充到圖的右側,我可以使用+ 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.) 分別為geom_point()
和geom_line()
) 添加了aes(color= id, shape= id)
和aes(color= id)
。
3.) 將show.legend= TRUE
添加到geom_point()
和geom_line()
。
4.) 在scale_color_manual()
中添加了aesthetics= "color"
。
palette
是包含顏色十六進制代碼的字符向量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.