【问题标题】:Change legend title in ggplot with both shape and color用形状和颜色更改ggplot中的图例标题
【发布时间】:2021-03-03 15:59:36
【问题描述】:

我正在尝试更改我的图例的标题,但我只知道如何使用 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)

【问题讨论】:

  • 不确定我是否正确。如果您想要一个带有自定义标题的颜色和形状图例,您可以通过labs(color = "Legend title", shape = "Legend Title") 来实现,即为“两个”图例赋予相同的名称。
  • 是的,非常感谢!

标签: r ggplot2 legend


【解决方案1】:

Stefan:不知道我说得对不对。如果您想要一个带有自定义标题的颜色和形状图例,您可以通过 labs(color = "Legend title", shape = "Legend Title") 来实现,即为“两个”图例赋予相同的名称。

【讨论】:

    猜你喜欢
    • 2021-02-07
    • 2020-11-24
    • 2023-03-16
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 2021-10-05
    相关资源
    最近更新 更多