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

  • Home
  • SEARCH
  • 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 6635635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:04:45+00:00 2026-05-25T23:04:45+00:00

I am using ggplot2 to plot simple line charts of time series data. One

  • 0

I am using ggplot2 to plot simple line charts of time series data. One difficulty I have run into is labelling specific points corresponding to x-axis values i.e. dates.

library(ggplot2)
library(scales)
date <- c("2011-09-19","2011-09-20","2011-09-21",
    "2011-09-22","2011-09-23","2011-09-26","2011-09-27")
price <- c(100,110,105,115,120,115,125)
tmp <- data.frame(date,price)
tmp$date <- as.Date(tmp$date)
p <- ggplot(tmp,aes(tmp$date,tmp$price))
p <- p + xlab("Date")
p <- p + ylab("Price")
p <- p + layer(geom = "line")
p <- p + opts(title="Simple price plot")
print(p)

What I would like to do is add an annotation to a specific date, which might be a maximum or a minimum value or something else of note. So far all the permutations of geom_text I have used have failed to get the effect I want (or indeed anything useful). There are a few questions on this on SO but most seem related to scatter charts rather than time series; I haven’t been successful in trying to adapt them. I have also spent some time with the documentation but my understanding is still limited. Any pointers would be appreciated.

  • 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-05-25T23:04:46+00:00Added an answer on May 25, 2026 at 11:04 pm

    To add text to ggplot, use geom_text:

    Method 1: Add a column of labels to your data.frame:

    tmp$note <- LETTERS[1:7]
    
    ggplot(tmp,aes(date, price, label=note)) +
      geom_line() +
      geom_text(vjust=0, colour="red")
    

    enter image description here

    Method 2: Add a specific label:

    ggplot(tmp,aes(date, price, label=date)) +
      geom_line() +
      geom_text(data=tmp[3, ], label="Something of note", vjust=1)
    

    enter image description here

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

Sidebar

Related Questions

I'm trying to understand how to have more than one series on a plot,
From the documentation for ggplot2's geom_tile() function, we have the following simple plot: #
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I am using ggplot2 to plot a figure that contains nine facets. Each facet
I'm using ggplot2 to make some bullseye charts in R. They look delightful, and
I'm plotting a group of curves, using facet in ggplot2. I'd like to have
I have a bunch of measurements over time and I want to plot them
I have simple histogram, but can't adjust the binwidth: qplot(factor(size_class),data=mydf,geom=histogram,binwidth = 0.01) size_class is
I'm using R. I have 25 variables over 15 time points, with 3 or
I am using ggplot2 to plot a pointrange() plot, and both the x and

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.