I would like to make each point on the graph a different color from the line. Here is sample data.
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")
Here is my code for the plot.
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)
I would like the green dots to be a darker green, the orange dots to be a darker orange and so forth.
You could use a filled point marker (shapes 21 through 25), which would allow you to set the fill colors for the points separately from the colors of the lines. In the code below, I use the same hues (the h
argument to the hcl
function) for the points and lines, but a lower luminance (the l
argument to hcl
) for the points so that they will be darker than the lines. I've also increased the line and point sizes to make it easier to see the difference.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With