0

Two part question: In ggplot, I am trying to increase the spacing between my axes intervals so that when I offset my "raw data" points next to the mean and confidence interval, it is more obvious that the data points belong to the rectangles on the left (e.g., if the gap between 1988 and 1989 was 1 inch on paper, how would I make it 2 inches)?

Secondly, I would like to know if there is a way to create breaks in the axes such that I can eliminate the white space in the years of missing data. Code is below but I am hoping for something that looks like this example

http://gnuplot-surprising.blogspot.com/2011/10/broken-axes-graph-in-gnuplot-3.html

set.seed(1)
mean<-rnorm(100,0,2)
years<-c(1988,1989,1990,2001,2002,2003,2012,2013,2014)
winter<-sample(years, 100,replace=T)
data<-as.data.frame(cbind(mean, winter))

library("Rmisc")
sum<-summarySE(data,measurevar="mean",groupvars=c("winter"))

library(ggplot2)
p<-ggplot(sum, aes(x=winter, y=mean, group=winter))+
geom_rect(aes(ymin=mean-ci, ymax=mean+ci, xmin=winter-.2, xmax=winter+.2), fill="gray")+
geom_point(shape=18, size=3)+
scale_x_continuous(breaks=seq(1985,2014,5))+
scale_y_continuous(breaks=seq(-2,4,1))+
geom_abline(intercept=0,slope=0, lty=2)+
theme_bw()

p2<-p + geom_point(data=data, aes(x=winter+.3,y=mean),shape=1, size=2.5)+
  scale_shape()
p2
Whitebeard
  • 5,945
  • 5
  • 24
  • 31
Michel Kohl
  • 81
  • 2
  • 6
  • Regarding the broken axes, the short answer is [no](http://stackoverflow.com/q/7194688/324364), at least for ggplot (although technically anything is possible to do manually in grid graphics, but it will be very difficulty). – joran Sep 18 '15 at 20:39

1 Answers1

0

As @joran stated, axis-breaks in ggplot are a no go. Facets generally offer the best solution. Maybe this will help you:

p<-ggplot(sum, aes(x=winter, y=mean, group=winter))+
  geom_rect(aes(ymin=mean-ci, ymax=mean+ci, xmin=winter-.2, xmax=winter+.2), fill="gray")+
  geom_point(shape=18, size=3)+
  scale_x_continuous(breaks=seq(1985,2014,1))+
  scale_y_continuous(breaks=seq(-2,4,1))+
  geom_abline(intercept=0,slope=0, lty=2)+
  theme_bw()

p2<-p + geom_point(data=data, aes(x=winter+.3,y=mean),shape=1, size=2.5)+
  scale_shape()
p2 + facet_wrap(~winter,nrow=1,scales="free_x")

enter image description here

BTW: have you considered using boxplot for this kind of data visualization?

RHA
  • 3,677
  • 4
  • 25
  • 48