[英]Change legend title in ggplot with both shape and color
我正在嘗試更改我的圖例的標題,但我只知道如何使用col
或shape
重命名它,這給了我一個額外的圖例 - 一個基於shape
一個基於col
。 有誰知道如何修復它,以便我得到一個帶有自定義標題的圖例,該標題顯示帶有shape
和col
的符號?
這是我的圖表:
mtcars
Library(ggplot2 )
library(ggpmisc)
formula <- y~x
ggplot(mtcars, aes(disp, drat, col=factor(cyl), shape=factor(cyl))) +
geom_point() +
geom_smooth(method = "lm",formula = formula) +
scale_color_manual(values=c("#000000", "#E69F00", "#56B4E9")) +
theme_bw() +
stat_poly_eq(
aes(label = paste(stat(adj.rr.label), stat(p.value.label), sep = "*\", \"*")),
formula = formula, parse = TRUE, size=3)
Stefan:不確定我是否理解你的意思。 如果您想要一個帶有自定義標題的顏色和形狀的圖例,您可以通過 labs(color = "Legend title", shape = "Legend Title") 來實現,即給“both”圖例賦予相同的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.