I want to draw a point-line chart of x-y-variables and highlight two groupings. I know some of the options to distinguish factors, like fill
, shape
, col
or group
. For the first group I would like to have color and for the second shape (which may or may not have the same color). And I need a legend to distinguish both groupings (which I already have). Perhaps I have to put aes in geom_line or geom_point, but I'm not sure. Since later on I would like to adjust size of the shapes (to better distinguish those).
- How to connect those points by colored lines?
- How to adjust size of the shape group?
Here is my code:
library(ggplot2)
data <- data.frame(id1=c(1,1,1,2,2,2,3,3,3,4,4,4),
id2=seq(1:3), year=seq(from=2007, to=2018, by=1),
variable=rep(c(5:8), each=3))
# two groups by color and shape, but it drops the line (seperate legends, thats nice)
ggplot(data, aes(x=year, y=variable, col=factor(id1), shape=factor(id2))) +
geom_line() + geom_point()
aes(group = id1)
to thegeom_line
to connect them by group. Adding something likesize = 2
outside of theaes
call will change the size of points/lines. – svenhalvorson