I have a function like this:
plotMeansDouble <- function(data, labX)
{
#xlabs <- paste(levels(stats::reorder(data$type, data$score,mean)),"\n(N=",levels(stats::reorder(data$N, data$score,mean)),"/",levels(stats::reorder(data$TN, data$score,mean)),")",sep="")
ggplot(data, aes(x=microstyle, y=difficulty, ymax = Upper.CI, group= course, color=course)) +
geom_errorbar(aes(ymin=Lower.CI, ymax = Upper.CI ), width=.1, position=position_dodge(.2)) +
geom_line(, position=position_dodge(.2)) +
geom_text(aes(y=Upper.CI,label = pointlabel, vjust=-1),position=position_dodge(.2)) +
geom_point(size=3, shape=21, position=position_dodge(.2))+
labs(x = labX, y = "Score") +
theme_bw()+
theme(panel.grid.major = element_blank(), panel.border = element_blank(),axis.text=element_text(size=14), axis.title=element_text(size=18),axis.text.x=element_text(size=16, angle=40, vjust=.8, hjust=1.01)) #+ scale_x_discrete(labels=xlabs)
}
This code plot my graph like this:
In this plot I want to plot the relationship between Type and Score for two courses, so far so good. But now I would like to add a second x-axis lables below A, B and C respectively to show the number of observations for each type. Note that in the code I commented the scale_x_discrete
. I know this function allows me to add something under each level. But the problem is that I have two courses DSP and RP. So I would like to add the number of observations for both two courses under x labels A,B,C, preferably colored with green and yellow to represent two courses, which does not seem to be possible with scale_x_discrete
.
I think a solution could be add two additional x-axis under the current one, each with labels of the two course. Is it possible to achieve this with ggplot2
?