Solved the jitter problem, now I want to make the points more visible. I chose pch=21
to have a black circle filled with colors. But, the boxes changed to the same color scheme. How can I change the box colors back? I'd like to have the same box colors in Figure A as in Figure B.
library(tidyverse)
library(ggpubr)
mtcars$cyl=factor(mtcars$cyl)
p1=mtcars %>% ggplot(aes(x=cyl, y=mpg, fill=cyl))+
geom_boxplot(show.legend = F, aes(fill=cyl))+
geom_point(position=position_jitterdodge(jitter.width=2, dodge.width = 0),
pch=21, aes(fill=factor(wt)), show.legend = F)
p2=mtcars %>% ggplot(aes(x=cyl, y=mpg, fill=cyl))+
geom_boxplot(show.legend = F)+
geom_point(position=position_jitterdodge(jitter.width=0, dodge.width = 0.3),
aes(color=factor(wt)), show.legend = F)
ggarrange(p1,p2,labels=c("A","B"))
ggplot
only allows you to map each aesthetic ones. See e.g. Hadley's answer here Multiple fill scales with seperate legends. Various work-arounds are therefore needed. – Henrik