簡體   English   中英

使用形狀和顏色更改ggplot中的圖例標題

[英]Change legend title in ggplot with both shape and color

我正在嘗試更改我的圖例的標題,但我只知道如何使用colshape重命名它,這給了我一個額外的圖例 - 一個基於shape一個基於col 有誰知道如何修復它,以便我得到一個帶有自定義標題的圖例,該標題顯示帶有shapecol的符號?

這是我的圖表:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM