r- ggplot2中散点线图的图例(无颜色)

  • 本文关键字:颜色 ggplot2 r ggplot2 legend
  • 更新时间 :
  • 英文 :


这是很新的,所以如果有一个明显的答案,我很抱歉。我想给带有2y变量的散点线图添加一个图例;我知道这可以使用颜色来完成,但是我理想地想要保持这种黑白,并通过linetype/point来定义图例中的变量。有什么办法可以做到吗?

ggplot(birds, aes(distance)) +geom_point(aes(y=individuals_AC)) +geom_point(aes(y=species_AC, shape=17)) +geom_line(aes(y=individuals_AC)) +geom_line(aes(y=species_AC, linetype="dashed")) + scale_shape_identity() + scale_linetype_identity() + theme_classic()

library(tidyverse)
#create some dummy data
df <- tibble(
x = runif(10),
y = runif(10),
type = rep(c("a", "b"), 5)
)
#plot it with a different shape for each type
df %>% 
ggplot(aes(x, y, shape = type)) + 
geom_point()

最新更新