1

Using ggplot I'm trying to add unique text to each facet in the plot below with geom_text but the horizontal position of the text is different in each. I want the text to be placed in the upper left corner of each facet. The first ten rows of the data set are listed below. Much thanks in advance for any help this question receives.

FM     x   PC Suitability   Output
1  Max 3.349 71.6         avg 9.20e-06
2  Max 3.997 71.6         avg 9.69e-06
3  Max 4.645 71.6         avg 1.02e-05
4  Max 5.293 71.6         avg 1.08e-05
5  Max 5.941 71.6         avg 1.13e-05
6  Max 6.589 71.6         avg 1.19e-05
7  Max 7.237 71.6         avg 1.26e-05
8  Max 7.885 71.6         avg 1.32e-05
9  Max 8.533 71.6         avg 1.39e-05
10 Max 9.181 71.6         avg 1.47e-05

p = ggplot(y1, aes(x, Output, group=FM, linetype=Suitability, size = 
Suitability)) + geom_line(aes(group=Suitability)) + 
facet_grid(~FM, scales = "free_x", ncol=2)+ scale_linetype_manual(values = 
c("solid","dashed","dashed"))+ scale_size_manual(values=c(.6,.5,.5))+
ylab("Prediction Values\n")+ xlab("\nRange of Values")+ 
theme(axis.text=element_text(size=9))+ theme_bw()+ 
theme(panel.border = element_blank(), axis.line = 
element_line())+theme(legend.position="none")

perc <- ddply(.data=y1, .(FM),summarize, n=paste(PC))
p+geom_text(data=perc, aes(x=.25, y=1,label=n), colour="black", 
inherit.aes=FALSE)

enter image description here

aosmith
  • 34,856
  • 9
  • 84
  • 118
  • can you provide a dataframe properly organised. – Al14 Jun 15 '17 at 20:24
  • you could use `x=-Inf` then justify it slightly .. Try `geom_text(data=perc, aes(x=-Inf, y=1, label=n), colour="black", inherit.aes=FALSE, hjust = -1)` – user20650 Jun 15 '17 at 20:44
  • Yes! That answer works perfectly...thank you. I found another solution and should have seen it before asking the question but the labels were placed exactly where the code commands them...at an x value of 0.25 and since I used scales = "free_x" the value 0.25 is different for each facet. The solution then is to use the following code: – Andrew Yost Jun 15 '17 at 21:12
  • geom_text(data=perc, aes(x=min(y1$x), y=1,label=n), colour="black", inherit.aes=FALSE) – Andrew Yost Jun 15 '17 at 21:13
  • I think x= -Inf is the better option though. – Andrew Yost Jun 15 '17 at 21:14

0 Answers0