ggplot2: group x axis discrete values into subgroups
I found this figure on the link above is very useful to create a grouping barchart. However, my question is that how could I change the angle of the letter a,b,c,... etc in the x axis? It worked okay when plotting it, but since I used another code to layout the Arabic letter, the sub-x axis did not rotate
My data is as follows:
rr <- df %>% count(college,department)
View(rr)
And I did the following code, it worked for the grouping value, and the sub-x axis labels did rotate. However, Arabic letters did not appear correctly.
zz<-ggplot(rr, aes(college, n, fill=department, label = department)) +
geom_bar(position="dodge", stat="identity") +
geom_text(position = position_dodge(width = 1), aes(x=college, y=0) ) +
theme(axis.title.y = element_text(size = rel(2), angle = 90), legend.position = "none") + ylim(0,140)+
theme(axis.text.x = element_text(angle = 60,size = rel(3), color="black"))
Now, I am using the following code in order to allow Arabic letters appear correctly, it did not rotate the sub-x axis when I override the previous code with the following:
gg<-ggplotly(zz) %>% layout(titlefont=list(size=10), yaxis = list(side="right", gridcolor = toRGB("gray90"),
gridwidth = 2, ticks="", title="عدد المحاضرات لكل قسم", titlefont=list(size=20)),
xaxis = list(ticks="", tickfont=list(size=14), title="الأقسام الأكاديمية", titlefont=list(size=30)),
margin = list(l = 50, r=30, b = 50, t = 80))
It appeared with vertical sub-x axis as follows:
But I am trying to rotate them in the second code, any answers would be really appreciated, thank you.