【问题标题】:geom_smooth and geom_point do not have legendsgeom_smooth 和 geom_point 没有图例
【发布时间】:2022-11-27 20:37:17
【问题描述】:

我想创建一个看起来像这样的情节:

x=1:20
y=sample(20)

df <- tibble(x=x,y=y)
ggplot(df,aes(x,y))+
  geom_smooth()+
  geom_point()

但代码无法显示图例。 谁能帮帮我,谢谢!

【问题讨论】:

    标签: r ggplot2 legend


    【解决方案1】:

    您可以将它们设置为 aes() 中的变量:

    x <- 1:20
    y <- sample(20)
    
    library(ggplot2)
    library(dplyr)
    
    df <- tibble(x=x,y=y)
    
    ggplot(df,aes(x,y))+
      geom_smooth(aes(color = "line"))+
      geom_point(aes(color = "point"))+
      scale_color_manual(values = c("blue","red"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 2017-11-29
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多