我正在使用线型来区分结果度量和使用符号形状来区分因子水平,针对同一图中的一个因子绘制两个不同的结果度量(y1和y2)。由于某种原因,我无法获得第二个结果度量的符号以接受所需的填充色。 y1符号正确绘制时带有黑色边框和白色填充,但是y2符号默认为红色填充。
下面是一个简单的代码示例。非常感谢您的帮助。
谢谢, 草药
R 3.5.2 / RStudio 1.1.463 / MacOS 10.14.2
library(ggplot2)
a <- rep(c("a1", "a2"), each = 2)
x <- rep(c(1, 2), times = 2)
y1 <- c(1:4)
y2 <- c(4:1)
df <- data.frame(a, x, y1, y2)
p <- ggplot(data = df, aes(x = x, y = y1, shape = a, group = a)) +
geom_line(linetype = "dashed") +
geom_line(data = df, aes(x = x, y = y2, shape = a, group = a))
p # Lines are correct
p <- p + geom_point (aes(x = x, y = y1, size = 4)) +
scale_shape_manual(values = c(21, 22)) +
geom_point(size = 4, fill = "#FFFFFF") +
geom_point (aes(x = x, y = y2, size = 4, fill = "#FFFFFF"))
p # Symbol shapes are correct but y2 symbols fill red rather than white