我想让图表上的每个点与线条颜色不同.这是样本数据.
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")
Run Code Online (Sandbox Code Playgroud)
这是我的情节代码.
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)
Run Code Online (Sandbox Code Playgroud)
我希望绿点是深绿色,橙色点是深橙色等等.
您可以使用填充点标记(形状21到25),这样您可以将点的填充颜色与线的颜色分开设置.在下面的代码中,我对点和线使用相同的色调(函数的h
参数hcl
),但点的亮度(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")
Run Code Online (Sandbox Code Playgroud)