Reputation: 151
I am trying to change the distance between boxplots in a ggplot2 figure. I have boxplots which show the data for different categories of products. The categories (x-axis) are discrete variables. I tried position_dodge which did not affect the distance between the boxplots. It worked when the x-axis was a continuous variable.
Which command would increase the distance between the boxplots when x-axis is discrete?
require(ggplot2)
dat<-rbind(data.frame(approach=1,product=1,value=seq(1,20,0.5)),
data.frame(approach=1,product=2,value=seq(5,15,0.3)),
data.frame(approach=1,product=3,value=seq(5,17,0.2)),
data.frame(approach=2,product=1,value=seq(1,13,0.3)),
data.frame(approach=2,product=2,value=seq(3,18,0.5)),
data.frame(approach=2,product=3,value=seq(4,25,0.7)),
data.frame(approach=3,product=1,value=seq(1,15,0.6)),
data.frame(approach=3,product=2,value=seq(3,16,0.5)),
data.frame(approach=3,product=3,value=seq(1,10,0.1)))
dat$product<-as.factor(dat$product)
gg1<-ggplot(dat,aes(x =product, y = value, width = 4)) +
geom_boxplot(position=position_dodge(1))
gg1
Upvotes: 1
Views: 422
Reputation: 4220
Not entirely clear but...Do you want to play with width
?
geom_boxplot(width=0.5)
produces
geom_boxplot(width=0.1)
produces
Upvotes: 1