Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:13:52+00:00 2026-06-17T20:13:52+00:00

Possible Duplicate: Annotating text on individual facet in ggplot2 I am working on a

  • 0

Possible Duplicate:
Annotating text on individual facet in ggplot2

I am working on a data-set with 3 species. They are apple, orange and banana.

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.

Here is my code:

library(ggplot2)
library(grid)

tempobs <- read.csv("temp data share.csv",header=T, sep=",")
p1 <- 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 <- 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 <- data.frame(x=c(340,390),y=c(3,3),id=c("orange"),label=c("2008","2009"))
p1 <- p1 + geom_text(data=ann_text,aes(x=x,y=y,label=label,size=3),show_guide=F)
p1

Now, I want to add the arrows and segment based on the overall graph.

My data can be found on https://www.dropbox.com/s/dfcmqrslskwdh80/temp%20data%20share.csv

My output is enter image description here

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.

enter image description here

The output shows the annotation I want but it is on all the facets. I want only on the bottom one.

Thank you so much.

Regards,
Jdbaba

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:13:53+00:00Added an answer on June 17, 2026 at 8:13 pm

    You should make a data frame (the same as for the text labels) also for values you want to use for the segment.

    ann_line<-data.frame(xmid=366,xmin=310,xmax=420,y0=0,y2=2,y=1,
        id=factor("orange",levels=c("apple","banana","orange")))
    

    Then use geom_segment() to plot all the elements

    p1 + geom_segment(data=ann_line,aes(x=xmid,xend=xmin,y=y,yend=y),arrow=arrow(length=unit(0.2,"cm")),show_guide=F)+
         geom_segment(data=ann_line,aes(x=xmid,xend=xmax,y=y,yend=y),arrow=arrow(length=unit(0.2,"cm")),show_guide=F)+
         geom_segment(data=ann_line,aes(x=xmid,xend=xmid,y=y0,yend=y2),show_guide=F)+   
         geom_text(data=ann_text,aes(x=x,y=y,label=label,size=3),show_guide=F)
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: I have a nested data structure / JSON, how can I access
Possible Duplicate: how to add a reference to the system.data.SQLite.dll to the windows phone
Possible Duplicate: How to rename java.exe/javaw.exe process? Hi, I am working on java desktop
Possible Duplicate: Removing First Annotation-MapView iOS I am working on mapview project. I have
Possible Duplicate: When do you use Java’s @Override annotation and why? From the javadoc
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.