我有一个有三条不同线条的情节.我希望其中一条线也有点.我也希望没有点的两条线比没有点的线更粗.我已经设法得到了我想要的情节,但我传说并没有跟上.
library(ggplot2)
y <- c(1:10, 2:11, 3:12)
x <- c(1:10, 1:10, 1:10)
testnames <- c(rep('mod1', 10), rep('mod2', 10), rep('meas', 10))
df <- data.frame(testnames, y, x)
ggplot(data=df, aes(x=x, y=y, colour=testnames)) +
geom_line(aes(size=testnames)) +
scale_size_manual("", values=c(0.5,1,1)) +
geom_point(aes(alpha=testnames), size=5, shape=4) +
scale_alpha_manual("", values=c(1, 0, 0))
Run Code Online (Sandbox Code Playgroud)

我可以删除第二个(黑色)图例:
ggplot(data = df, aes(x=x, y=y, colour=testnames)) +
geom_line(aes(size=testnames)) +
scale_size_manual("", values=c(0.5,1,1), guide='none') +
geom_point(aes(alpha=testnames), size=5, shape=4) +
scale_alpha_manual("", values=c(1, 0.05, 0.05), guide='none')
Run Code Online (Sandbox Code Playgroud)

但我真正想要的是两个传说的合并 - 一个带颜色的图例,仅在第一个变量(meas)上交叉,mod1并且mod2比第一行更粗.我尝试过引导和覆盖,但运气不佳.
您不需要透明度来隐藏形状mod1和mod2.你可以通过它们的形状设置为忽略从情节和传说这些点NA在scale_shape_manual:
ggplot(data = df, aes(x = x, y = y, colour = testnames, size = testnames)) +
geom_line() +
geom_point(aes(shape = testnames), size = 5) +
scale_size_manual(values=c(0.5, 2, 2)) +
scale_shape_manual(values=c(8, NA, NA))
Run Code Online (Sandbox Code Playgroud)
这给出了以下图:

注意:我在尺寸比例和另一个形状中使用了一些更明确的值,以便更好地说明效果.