I'm trying to generate two kinds of labels on the x axis with R
ggplot2 package.
One is based on x axis's value (which I have already done), another one is based on pathId
(showing on the bar). Currently I'm putting them inside the bar using geom_text
.
Is there a way to put them under the x axis?
I see some questions here but they are based on stack bar or use x=interaction(var1,var2)
. But in that way each bar will have the same distance, which is not what I want.
Here is the data I generated by summarySE
:
pathId nodeId N value sd se ci
1 least similar 0 216 159.7242 96.74438 6.582622 12.97474
2 least similar 1 165 146.0958 123.27584 9.597011 18.94963
3 less similar 0 216 185.6628 149.27098 10.156604 20.01927
4 less similar 1 152 152.0290 135.02925 10.952318 21.63958
5 similar 0 216 179.3326 150.55189 10.243758 20.19105
6 similar 1 141 163.1733 111.77780 9.413389 18.61077
7 more similar 0 216 183.8146 123.51216 8.403938 16.56466
8 more similar 1 90 179.3577 141.21904 14.885794 29.57775
9 most similar 0 216 187.6143 107.80367 7.335111 14.45794
10 most similar 1 61 184.9422 117.32353 15.021738 30.04795
And the code I'm using is:
ggplot(data=bar_data, aes(x=interaction(nodeId), y=value, order=pathId), fill="grey80",colour="grey80")+
geom_bar(stat="identity", position="dodge", fill="grey95", colour="black", show_guide=FALSE)+
geom_errorbar(aes(ymin=value-se, ymax=value+se, order=pathId), width=.15,
colour="black", position=position_dodge(width=0.90))+
ylab("BM25 Score")+
xlab("Node")+
scale_x_discrete(breaks= c(0,1),
labels=c("BM25(Node0, Node1)","BM25(Node1, Node2"))+
geom_text(data=bar_data, aes(label=pathId, y=30),position=position_dodge(width=0.9),angle=75)+
theme(legend.title=element_text(size=14), legend.text=element_text(size=12))+
theme_bw()+
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank())
This graph is what I get.
And this is what I want, I also want the label for group members can be rotated so I could write longer string for each of them.