Dear all,
I have some data with two categorical predictors and a continuous respons:
age <- factor(rep(rep(c("young", "old"), each = 5), 2), levels = c("young", "old"))
sex <- rep(c("f", "m"), each = 10)
mass <- rnorm(20)
dd <- data.frame(sex, age, mass)
I wish to use ggplot to create something like this:
boxplot(mass ~ age:sex, data = dd, at = at1, axes = FALSE, xlab = "", ylab = "")
box()
axis(side = 1, line = 0, at = at1, tck = 0.01, las = 1, lwd = 1, cex.axis = 1.5, labels = FALSE)
axis(side = 2, hadj = 0.7, line = 0, tck = 0.01, las = 1, lwd = 1, cex.axis = 1.5)
mtext(side = 1, line = 0.5, text = c("young", "old"), at = at1, cex = 1.5)
mtext(side = 1, line = 2.5, text = c("female", "male"), at = at2, cex = 1.5)
mtext(side = 2, line = 2.5, text = "Body mass (g)", cex = 1.5)
Here I set the horisontal position of both boxes, ticks and text is set with the at-argument.
Now for ggplot.
What I am struggling is to find an argument similar to 'at' in ggplot2, or another appropriate method, to set the position of ticks and text for the x-axis. (colours, background, grid etc is not an issue at this stage)
This:
ggplot(data = dd,
mapping = aes(x = sex, y = mass, fill = age)) +
geom_boxplot() +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank())
...seems to put the ticks according to the two levels of x. Fair enough.
I haven't manage to find anything on ?theme / axis.text / element_text, or axis.tick / element_line on how to set the position of these element.
I just tried to specify the 'aes(x = ' in a similar way as the boxplot example to see if tick marks are placed differently. However, aes(x = sex:age, ... and aes(x = sex + age ..., both without the fill-argument, gives an error.
I am not able to find anything on ?aes and ?aes.string of how to specify two x-terms (without knowing if this would improve the tick marks), like in the boxplot example.
Thanks in advance for your help!
Best regards,
HenriksessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit)
...ggplot2_0.9.2.1