sorry for the poor header, but I was struggling to find the right wording. I hope you understand my question.
I would like to create a chart where I first draw all red elements (both lines and points) and then all all elements blue elements (both lines and points). In other words first draw everything for group==1 and then all elements for group==2. I've achieved what I want with fig2 below, but it just feels very inefficient. Is there a better way to do it?
Thank you, Hans
# Load library
library("tidyverse")
library("patchwork")
# Some data
df<-tibble(x=c(1,2,5,3,4,4),y=c(1,2,4,5,3,6),group=c(1,1,1,2,2,2))
# Plot
fig1<-ggplot(df,aes(x=x,y=y,color=as.factor(group)))+
geom_point(size=20)+
geom_line(size=2)+
theme(legend.position = "top")+labs(title="Not what I want")
# Manual
fig2<-
ggplot(df,aes(x=x,y=y,color=as.factor(group)))+
geom_point(,size=20)+
geom_line(size=2)+
geom_point(df%>%filter(group==1),mapping=aes(x=x,y=y,color=as.factor(group)),size=20, color="#F8766D")+
geom_line(df%>%filter(group==1),mapping=aes(x=x,y=y,color=as.factor(group)),size=2, color="#F8766D")+
geom_point(df%>%filter(group==2),mapping=aes(x=x,y=y,color=as.factor(group)),size=20, color="#00BFC4")+
geom_line(df%>%filter(group==2),mapping=aes(x=x,y=y,color=as.factor(group)),size=2, color="#00BFC4")+
theme(legend.position = "top")+labs(title="What I want")
fig2
fig1+fig2
