I’m having some trouble with the geom_text combined in facet_wrap function in RStudio.
I wanted to insert the R^2 of each function in each graph created with the ggplot2 library.
I’ve summyrised the R^2 of each function in a dataframe using the following code:
df_R_DENSITY<-data.frame(Trial=c("A","B","C","D","E","F","G","H","I","L"),
R = c("italic(R^2) == 0.865", "italic(R^2) == 0.908", "italic(R^2) == 0.887", "italic(R^2) == 0.890", "italic(R^2) == 0.854", "italic(R^2) == 0.825", "italic(R^2) == 0.895", "italic(R^2) == 0.926", "italic(R^2) == 0.864", "italic(R^2) == 0.798"))
I then created the graph using the following code:
ggplot()+
geom_hline(yintercept = 25, size=0.5, alpha = 0.6, color="gold2") +
geom_hline(yintercept = 35, size=0.5, alpha = 0.6, color="cyan3") +
geom_hline(yintercept = 60, size=0.5, alpha = 0.6, color="magenta") +
geom_point(data = df,aes(x=MetriCorrectetd,y=Droplets.cm2), size=0.2, colour="blue")+
geom_line(data = DF_Predicted_Density,aes(x=MetriCorrectetd,y = Predicted), size=0.8, colour = "green3", alpha = 0.8)+
facet_wrap(~ LABEL, ncol=2)+
geom_text(x = 4.5, y = 225, aes(label = R), data = df_R_DENSITY, parse = T, hjust = 0)+
ylim(0,250)+
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 24),
axis.title = element_blank(),
strip.text.x = element_text(size = 14, face = "bold"),
strip.background=element_rect(fill="coral2"))
But the R^2 are superimposed on each other in each facet of the graph. As you can see in the picture.
How can I solve this problem?
Andrea Pagliai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.