I am creating a plot showing available data for experimental installations using ggplot. My problem is that the y-axis becomes too crowded, so I would like to have every other tick mark be longer, allowing me to use a larger font for the axis labels.
My goal is to plot the field installation number versus age at measurement, showing all of the available data, and sorted by the age at first measurement. Here is an example using pseudo-data. Note that the plotting order of the installations on the y-axis is based on the age at first measurement.
# create data frame of fake values
set.seed(1)
plots <- data.frame(installation=rep(sample(seq(1,100,1), 10), each=10),
age=as.vector(replicate(10, sample(seq(1,50,1), 10))))
# set up installations as factor, sorted by age at first measurement
odr <- ddply(plots, .(installation), summarize, youngest = min(age))
odr <- odr[order(odr$youngest),]
plots$installation <- factor(plots$installation, levels=rev(as.numeric(as.character(odr$installation))))
rm(odr)
# plot the available data
ggplot(plots, aes(installation, age)) +
geom_point() +
coord_flip()
I've actually got about 60 installations and a label for each, so it gets crowded. By staggering every other y-axis tick out a little longer I can use a larger font for the labels. This is the question I am hoping to get answered.
I tried plotting the even and odd factors separately, which would then allow me to fiddle with the axis marks for each, but the ordering got screwed and I'm not sure why. If there is a way to get the axis tick effect I'm after another way I'm not married to this approach.
# break up the data frame into odd and even factors
odds <- plots[as.numeric(plots$installation) %% 2 != 0,]
evens <- plots[as.numeric(plots$installation) %% 2 == 0,]
# try and plot odds and evens seperately
ggplot(odds, aes(installation, age)) +
geom_point() +
coord_flip() +
geom_point(data = evens, aes(installation, age))