[英]Draw a line between points of different shapes in ggplot2
Here is some dummy data这是一些虚拟数据
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))
I would like to draw a line linking the points in the different colors.我想画一条线连接不同颜色的点。 Because I would like to keep a space between the line and the point, I am using geom_pointline
from the package lemon
因为我想在线和点之间保留一个空格,所以我使用了包lemon
geom_pointline
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))
My issue is that the line does not connect points of different shapes together.我的问题是这条线没有将不同形状的点连接在一起。 How can I solve this problem?我怎么解决这个问题?
Maybe aes(group = color)
is what you want.也许aes(group = color)
是你想要的。
library(lemon)
ggplot(d, aes(x = x, y = y)) +
geom_pointline(aes(group = color, color = color, shape = shape))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.