【问题标题】:How to add labels to multiple curves on ggplot?如何为ggplot上的多条曲线添加标签?
【发布时间】:2021-11-14 01:38:42
【问题描述】:

我正在尝试将曲线名称直接从图例中添加到我的 ggplot 中。

这是我的代码

plott = ggplot(PL2, aes(P, growth.rate2020, color=Country, showlabels=TRUE)) + 
    geom_point()

我想看到的是每条曲线旁边的每个国家的名字

【问题讨论】:

标签: r ggplot2 ggpubr


【解决方案1】:

您可以添加geom_label并删除图例指南:

library(tidyverse)

iris %>%
  ggplot(aes(Sepal.Length, Petal.Length, color = Species)) +
  geom_point() +
  geom_label(
    data = iris %>% group_by(Species) %>% summarise(across(everything(), mean)),
    mapping = aes(label = Species, x = 5)
  ) +
  guides(color = FALSE)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.

reprex package (v2.0.1) 于 2021-09-20 创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 2021-12-12
    • 2016-05-17
    • 1970-01-01
    • 2020-04-29
    相关资源
    最近更新 更多