Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R- Group jitter in factored boxplot? [duplicate]

Tags:

r

ggplot2

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.

enter image description here

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))
like image 771
ElPresidente Avatar asked Jun 03 '14 14:06

ElPresidente


1 Answers

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())
like image 94
ElPresidente Avatar answered Nov 01 '22 15:11

ElPresidente