I am using ggplot2 to plot two different discrete variables on the same graph, and the breaks I obtained for the two variables are obviously different. I would like to label the breaks on the x-axis with superimposed values of said labels, rather than next to one another, which I managed to do but did not really work on a small graph (labels overlapping).
This is the code I am using:
plot<-ggplot(data, aes(xcut,modx, group=1))+
geom_smooth(aes(color="red"), se=F, linetype="dotted", size=1.25)+
geom_line(data=data,aes(xcut,lowerx, color="red4"), size=1.5)+
geom_line(data=data,aes(xcut,upperx, color="red4"), size=1.5)+
geom_ribbon(data=data, aes(xcut,ymin=lowerx,ymax=upperx), fill="lightpink", alpha=0.4)+
geom_smooth(data=databis, aes(xcut,modx, group=1, color="green"), se=F, linetype="dotted", size=1.25)+
geom_line(data=databis,aes(xcut,upperx, color="green4"), size=1.5)+
geom_line(data=databis,aes(xcut,lowerx, color="green4"), size=1.5)+
geom_ribbon(data=databis, aes(xcut,ymin=lowerx,ymax=upperx), fill="chartreuse1", alpha=0.4)+
ylim(min(data$lowerx,databis$lowerx),max(data$upperx,databis$upperx))+
scale_colour_manual(name = 'Legend',
values =c('red'='red','green'='green', 'green4'='green4', 'red4'='red4'), labels = c('','','',''))+
scale_size_area() +
xlab("") +
ylab("")+
labs(title='')
plot<-plot + scale_x_discrete(breaks=c(1:10), labels=c(label6Ex$label))
I am sorry that I cannot provide a working example, due to the amount of data that would require. Basically I use the "x" variable, a related "modx" variable and a discrete variable "xcut" that is just "x" cut with ten breaks. I have two different dataframes (data and databis) where all variables have been similarly defined, but obviously the labels are different for both dfs. The labels I add in the end have been separately determined; as I said I have tried to add the two labels for each break as such:
plot<-plot + scale_x_discrete(breaks=c(1:10), labels=c(paste(labeldatax$label,labeldatabisx$label,sep=" - ")))
Which gives me this graph for the x and xbis variables with both labels
But it would be more convenient for me to have both labels superimposed vertically. Any help on the matter would be welcome!
Thanks in advance.