Assume I have a dataframe df:
Day Value Group
1 1 1
2 5 1
3 10 2
4 15 2
5 20 1
I would like to trend a single line on df, x = Day & y = Value, but with each points colored based on Group
Here's a rough illustration for better understanding:
Please advise
You can apply the color=
aesthetic to only one layer if needed.
library(ggplot2)
ggplot(dat, aes(Day, Value)) +
geom_line() +
geom_point(aes(color = factor(Group)), size = 2)
Data:
dat <- read.table(header=TRUE, text="
Day Value Group
1 1 1
2 5 1
3 10 2
4 15 2
5 20 1")