I created three plots in ggplot2 to show the sex ratio in a panel dataset over different years.
Everything worked well, but when labeling the points of the graph and then putting them together with ggarrange some of the lables just drop out of the graph and cannot be read anymore or they overlap even thought I specified position = position_dodge.
I created the plots with the following code:
plot1 <-
ggplot(data, aes(x = Year, y = perc*100, colour = Sex)) +
geom_path(aes(group=Sex)) +
geom_point() +
scale_color_manual(values=c("skyblue3", "darkred"))+
labs(title = "Sex Ratio", x = "years", y = "percentage") +
theme(plot.title = element_text(hjust = 0.5), panel.grid.major.x = element_blank()) +
geom_text(aes(label = paste0(round(perc*100), "%")), position = position_dodge(width =1), vjust = 2, size = 2.5, colour = "black", check_overlap = TRUE)
I did this for all the three plots and then I tried to arrange them with ggarrange in the following way:
plot_together <- ggarrange(plot1, plot2, plot3, ncol = 2, nrow = 2,
common.legend = TRUE, legend = "bottom")
What I get is:
I don’t know how to solve the problem that some of the labels are not seen anymore.
I am only able to put all the labels together above or below, but not single ones above and other ones below or something like that.
Is one of you having an idea how to solve this?
Thank you in advance!
Manuel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2