I was trying to make a plot showing how many genes with functional annotations are present across my pipeline and connect the dots to show the connection between different boxplot and geom jitter.
But then I got stuck where the lines wouldn't connect to the dots because the position_jitter
was somehow different.
The original code was:
tt %>%
left_join(phylo %>% select(!NCBI_TaxID), by=c("Genome"="ID")) %>%
filter(Order %in% c("Bacillales","Enterobacterales","Flavobacteriales")) %>%
ggplot(aes(x=tool,y=n,col=Order,group=Genome))+
#geom_boxplot()+
geom_line(position = position_jitter(width = 0.25, seed = 123), col="gray80")+
geom_point(position = position_jitter(width = 0.25, seed = 123))+
theme_minimal()+
facet_wrap(~Order, scales = "free")
turns out the geom_line
function sort the data to make sure it goes into one direction. It sorts the data by x
, then group
and if you have a facet
it needs to go first.
Correct code:
tt %>%
left_join(phylo %>% select(!NCBI_TaxID), by=c("Genome"="ID")) %>%
filter(Order %in% c("Bacillales","Enterobacterales","Flavobacteriales")) %>%
mutate(tool=factor(tool, levels=c("All","Patric","Bakta","IMG","Prokka"))) %>%
arrange(Order,Genome,tool) %>%
ggplot(aes(x=tool,y=n,col=Order))+
geom_boxplot()+
geom_line(aes(group=Genome),position = position_jitter(width = 0.25, seed = 123), col="gray80")+
geom_point(aes(group=Genome),position = position_jitter(width = 0.25, seed = 123))+
theme_minimal()+
facet_wrap(~Order, scales = "free")
Final figure:
Error mentionned here