3
我使用geom_polygon重叠数据,但是由于它们合并在一起,因此无法区分颜色。这使得它更多的层次更糟糕。使用alpha和geom_polygon时防止混合
你如何确保颜色不混合?
的样本数据
newdat <- structure(list(x = c(0, 0.77, 1.54, 2.31, 3.08, 3.85, 4.62, 5.38,
6.15, 6.92, 7.69, 8.46, 9.23, 10, 10.77, 11.54, 12.31, 13.08,
13.85, 14.62, 15.38, 16.15, 16.92, 17.69, 18.46, 19.23, 20, 20.77,
21.54, 22.31, 23.08, 23.85, 24.62, 25.38, 26.15, 26.92, 27.69,
28.46, 29.23, 30, 0, 0.77, 1.54, 2.31, 3.08, 3.85, 4.62, 5.38,
6.15, 6.92, 7.69, 8.46, 9.23, 10, 10.77, 11.54, 12.31, 13.08,
13.85, 14.62, 15.38, 16.15, 16.92, 17.69, 18.46, 19.23, 20, 20.77,
21.54, 22.31, 23.08, 23.85, 24.62, 25.38, 26.15, 26.92, 27.69,
28.46, 29.23, 30), y = c(0, 0, 0, 0, 0, 0, 0.01, 0.01, 0.02,
0.03, 0.04, 0.05, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.05, 0.04,
0.03, 0.03, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0.01, 0.02, 0.03, 0.05,
0.06, 0.08, 0.09, 0.1, 0.1, 0.1, 0.1, 0.09, 0.08, 0.07, 0.06,
0.05, 0.05, 0.05, 0.04, 0.03, 0.02, 0.01, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), type = c("a", "a", "a", "a", "a", "a", "a", "a",
"a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a",
"a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a",
"a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b",
"b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b",
"b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b",
"b", "b", "b", "b", "b", "b", "b")), .Names = c("x", "y", "type"
), row.names = c(NA, -80L), class = "data.frame")
代码
library(ggplot2)
# Using polygon blends colors
ggplot(newdat, aes(x = x, y = y, fill = type)) + geom_polygon(alpha = 0.1)
# But using line shows they are different
ggplot(newdat, aes(x = x, y = y, color = type)) + geom_line()
地块