我想让图表上的每个点都与直线颜色不同。这是示例数据。
df <- structure(list(yrmonth = structure(c(17167, 17167, 17167, 17198,
17198, 17198, 17226, 17226, 17226, 17257, 17257, 17257), class = "Date"),
index = structure(c(2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
1L, 3L), .Label = c("E-W", "N-S", "OS"), class = "factor"),
N = c(2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1), data = c(129,
141, 27, 150.5, 209, 87, 247.5, 243, 188, 223, 226.5, 170
)), .Names = c("yrmonth", "index", "N", "data"), row.names = 31:42, class = "data.frame")
这是我的情节代码。
df$yrmonth <- lubridate::ymd(df$yrmonth)
ggplot(df, aes(x=yrmonth,y=data,colour=factor(index), group=index)) +
geom_line(size=.4) +
geom_point(size=1)
我希望绿点是深绿色,橙色点是深橙色等等。
最佳答案
您可以使用填充点标记(形状 21 到 25),这将允许您将点的填充颜色与线的颜色分开设置。在下面的代码中,我对点和线使用相同的色调(hcl
函数的 h
参数),但亮度较低(l
参数到 hcl
) 的点,以便它们比线条更暗。我还增加了线条和点的大小,以便更容易看出差异。
ggplot(df, aes(x=yrmonth,y=data)) +
geom_line(size=1, aes(colour=factor(index))) +
geom_point(size=3, aes(fill=factor(index)), shape=21, colour="#FFFFFF00") +
scale_colour_manual(values=hcl(seq(15,375,length=4)[1:3], 100, 70)) +
scale_fill_manual(values=hcl(seq(15,375,length=4)[1:3], 100, 40)) +
theme_classic() +
labs(colour="Index", fill="Index")
关于r - ggplot2:使线上的点颜色比线颜色深,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44597946/