Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding annotation (segment / arrow) in only certain facet ggplot
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11889625/annotating-text-on-individual-facet-in-ggplot2">Annotating text on individual facet in ggplot2</a> </p> </blockquote> <p>I am working on a data-set with 3 species. They are apple, orange and banana. </p> <p>I want to annotate the facets only on the bottom panel. However, by default I am getting annotations on all the plots. I was able to get text annotation only on the desired plot. However, I am confused what I need to do for the arrows / segments. </p> <p>Here is my code:</p> <pre><code>library(ggplot2) library(grid) tempobs &lt;- read.csv("temp data share.csv",header=T, sep=",") p1 &lt;- ggplot(tempobs,aes(x=time,y=data))+geom_point(data=tempobs,aes(x=time,y=data,colour=group1))+facet_wrap(~id,ncol=1)+theme_bw() p1 &lt;- p1 + xlab("Julian Day (2008-2009)")+ylab(expression(Temperature~(degree*C)))+ element_blank()+ theme( legend.position="right", legend.direction="vertical", legend.title = element_blank()) +coord_cartesian(xlim=c(250,550))+coord_cartesian(ylim=c(0,40))+scale_x_continuous(breaks=c(250,300,350,400,450,500,550),labels=c("250","300","350","34","84","134","184")) p1 ### This is how it should look like (though shows annotations for all the plots) p + annotate("text",x=340,y=3,label="2008",size=3)+annotate("segment",x=366,xend=366,y=0,yend=2,size=0.5)+annotate("text",x=390,y=3,label="2009",size=3)+annotate("segment",x=366,xend=310,y=1,yend=1,size=0.5,arrow=arrow(length=unit(0.2,"cm")))+annotate("segment",x=366,xend=420,y=1,yend=1,size=0.5,arrow=arrow(length=unit(0.2,"cm"))) ### This is what I did to show text annotation on the bottom panel ann_text &lt;- data.frame(x=c(340,390),y=c(3,3),id=c("orange"),label=c("2008","2009")) p1 &lt;- p1 + geom_text(data=ann_text,aes(x=x,y=y,label=label,size=3),show_guide=F) p1 </code></pre> <p>Now, I want to add the arrows and segment based on the overall graph. </p> <p>My data can be found on <a href="https://www.dropbox.com/s/dfcmqrslskwdh80/temp%20data%20share.csv" rel="nofollow noreferrer">https://www.dropbox.com/s/dfcmqrslskwdh80/temp%20data%20share.csv</a></p> <p>My output is <img src="https://i.stack.imgur.com/dOuBO.png" alt="enter image description here"> </p> <p>This is what I got with only text annotation. But for segment annotation I always got error. You can notice text labels 2008 and 2009 added on the bottom panel. </p> <p><img src="https://i.stack.imgur.com/2sPYg.png" alt="enter image description here"></p> <p>The output shows the annotation I want but it is on all the facets. I want only on the bottom one. </p> <p>Thank you so much.</p> <p>Regards, Jdbaba</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload