【问题标题】:Draw a line between points of different shapes in ggplot2在ggplot2中不同形状的点之间画一条线
【发布时间】:2020-03-31 00:20:03
【问题描述】:

这是一些虚拟数据

d = data.frame(
  x = rep(1:8,2),
  y = c(1,1.2,1.5,2,2.6,2.9,3.1,3.2,0.7,1,1.2,1.9,2.4,2.62,2.95,2.95),
  color = rep(LETTERS[1:2], each=8),
  shape = c(rep("a",6), rep("b",2), rep("a", 5), rep("b",3))
)


ggplot(d, aes(x=x,y=y,color=color,shape=shape)) + geom_point() + scale_colour_manual(values=c("darkblue", "darkred")) + scale_shape_manual(values = c(19,1))

我想画一条线连接不同颜色的点。因为我想在线和点之间保留一个空格,所以我使用包中的geom_pointline lemon

ggplot(d, aes(x=x,y=y,color=color,shape=shape)) + geom_pointline() + scale_colour_manual(values=c("darkblue", "darkred")) + scale_shape_manual(values = c(19,1))

我的问题是这条线没有将不同形状的点连接在一起。我该如何解决这个问题?

【问题讨论】:

    标签: r ggplot2 plot graphics


    【解决方案1】:

    也许aes(group = color) 就是你想要的。

    library(lemon)
    
    ggplot(d, aes(x = x, y = y)) +
      geom_pointline(aes(group = color, color = color, shape = shape))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2013-05-07
      相关资源
      最近更新 更多