I create charts that have two lines in the axis text. The first line contains the name of the group, the second line contains this group. I build my axis labels as a single character string with the format "LINE1 \ n LINE2". Is it possible to assign different faces and sizes of the LINE1 and LINE2 fonts, although they are contained in the same character string? I would like LINE1 to be large and bold, and LINE2 to be small and loose.
Here is a sample code:
Treatment <- rep(c('T','C'),each=2) Gender <- rep(c('Male','Female'),2) Response <- sample(1:100,4) test_df <- data.frame(Treatment, Gender, Response) xbreaks <- levels(test_df$Gender) xlabels <- paste(xbreaks,'\n',c('POP1','POP2')) hist <- ggplot(test_df, aes(x=Gender, y=Response, fill=Treatment, stat="identity")) hist + geom_bar(position = "dodge") + scale_y_continuous(limits = c(0, 100), name = "") + scale_x_discrete(labels=xlabels, breaks = xbreaks) + opts( axis.text.x = theme_text(face='bold',size=12) )
I tried this, but the result was one large, bold record and one small, loose record:
hist + geom_bar(position = "dodge") + scale_y_continuous(limits = c(0, 100), name = "") + scale_x_discrete(labels=xlabels, breaks = xbreaks) + opts( axis.text.x = theme_text(face=c('bold','plain'),size=c('15','10')) )
Another possible solution is to create separate chart elements, but I don't think ggplot2 has an available sub-axis element ...
Any help would be greatly appreciated.
Cheers, Aaron
r ggplot2
Aaron Jul 11 '11 at 16:16 2011-07-11 16:16
source share