R- Group jitter in factored boxplot?

ggplot2, r

Solution

Solution provided in comments by Didzis Elferts and link to this question

sData<-droplevels(subset(sData,STORE_TYPE=='Test'))

ggplot(sData,aes(x=factor(MARKET_NAME),y=DST_UNITS,fill=factor(PROGRAM_STATUS,c("PRE-PROGRAM","POST-PROGRAM")))) +
  geom_boxplot(outlier.shape=NA) + 
  geom_point(position=position_jitterdodge())

Problem

Is it possible to group the jitter in a boxplot like mine so that the data points line up with the factor for each market? Right now it's lining up by market name. I colored them to show which ones should be grouped. My code ``` p<-ggplot(droplevels(subset(sData,STORE_TYPE=='Test')),aes(factor(MARKET_NAME),DST_UNITS)) p + geom_boxplot(aes(fill=factor(PROGRAM_STATUS,c("PRE-PROGRAM","POST-PROGRAM")), outlier.shape=NA) + geom_jitter(aes(color=factor(PROGRAM_STATUS,c("PRE-PROGRAM","POST-PROGRAM"))),position=position_jitter(width=0)) ```

Original source

Related problems