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 6784163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:57:24+00:00 2026-05-26T16:57:24+00:00

I am plotting a dataset using the following: plot = ggplot(transData, aes(x=Time, y=Value)) +

  • 0

I am plotting a dataset using the following:

plot =  ggplot(transData, aes(x=Time, y=Value)) + 
        scale_fill_brewer(palette="Set1") + 
        facet_grid(Category ~ .) + 
        geom_line(aes(group=Type,colour=Type, linetype=Type), size=1.5) +
        geom_vline(...) +
        geom_text(...)

which draws a grid plot between Category and Type in my dataset. However, the geom_vline and geom_text make the vertical line and text label appear on every sub plot. Is there a way to to get a single vline and text element on the entire plot? Any suggestions?

Dataset

Class$Time$Type$Total
Class1$283$Category1$1
Class1$276$Category1$1
Class1$260$Category1$1
Class1$450$Category1$1
Class1$572$Category1$9
Class1$667$Category1$9
Class1$535$Category1$10
Class1$579$Category1$10
Class1$522$Category1$12
Class1$231$Category1$12
Class1$774$Category1$13
Class1$7240$Category1$14
Class1$510$Category1$14
Class1$3863$Category1$14
Class1$954$Category1$15
Class1$455$Category1$15
Class1$644$Category1$15
Class1$1859$Category1$15
Class1$413$Category1$16
Class1$13$Category1$19
Class1$22$Category1$19
Class1$13$Category1$19
Class1$14$Category1$19
Class1$523$Category1$19
Class1$123$Category1$19
Class1$684$Category1$19
Class1$350$Category1$19
Class1$581$Category1$19
Class1$28$Category2$18
Class1$18$Category2$18
Class1$17$Category2$18
Class1$73$Category2$18
Class1$17$Category2$18
Class1$18$Category2$18
Class1$17$Category2$18
Class1$73$Category2$18
Class1$25$Category2$18
Class1$74$Category2$18
Class1$18$Category2$18
Class1$78$Category2$18
Class1$19$Category2$18
Class1$75$Category2$18
Class1$51$Category2$18
Class1$24$Category2$18
Class1$32$Category2$18
Class1$94$Category2$18
Class1$80$Category2$18
Class1$19$Category2$18
Class1$34$Category2$18
Class1$73$Category2$18
Class1$28$Category2$18
Class1$78$Category2$18
Class1$84$Category2$18
Class1$77$Category2$18
Class1$85$Category2$18
Class1$80$Category2$18
Class1$82$Category2$18
Class1$72$Category2$18
Class1$17$Category2$18
Class1$87$Category2$18
Class1$78$Category2$18
Class1$74$Category2$18
Class1$74$Category2$18

Script

library(ggplot2)

options(stringsAsFactors = FALSE)
rootdir = "./"
input = paste(rootdir, "Test.txt", sep="")

data = data.frame(Class=data$Class, Type=data$Type, Time=as.numeric(data$Time), Total=as.numeric(data$Total))

plot =  ggplot(data, aes(x=Time, y=Total)) + 
        scale_fill_brewer(palette="Set1") + 
        facet_grid(Type ~ Class) + 
        scale_x_log10() +
        geom_line(aes(group=Type,colour=Type, linetype=Type), size=1.5) + 
        geom_vline(aes(xintercept=1), linetype=2) +
        geom_vline(aes(xintercept=4), linetype=2) +
        geom_vline(aes(xintercept=8), linetype=2) +
        geom_vline(aes(xintercept=16), linetype=2) +
        geom_text(aes(1, 4, label="Label1")) +
        geom_text(aes(4, 3, label="Label2")) +
        geom_text(aes(8, 25, label="Label3")) +
        geom_text(aes(16, 2, label="Label4")) +


print(plot)

options(stringsAsFactors = TRUE)

Plot

enter image description here

What I want

What is want is that the labels appear only once across the entire plot.

  • 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-26T16:57:24+00:00Added an answer on May 26, 2026 at 4:57 pm

    here is a quick example:

    dat.vline <- data.frame(Type = c("Category1", "Category2"), xp = c(1000, 4000))
    dat.text <- data.frame(Type = c("Category1", "Category2"), x = c(1000, 4000), y = c(5, 10), label = c("hoge", "boke"))
    
    ggplot(d, aes(Time, Total)) + 
      facet_grid(Type ~ .) + 
      geom_line(aes(group = Type, colour = Type, linetype = Type), size = 1.5) +
      geom_vline(aes(xintercept = xp), data = dat.vline) +
      geom_text(aes(x, y, label = label), data = dat.text)
    

    the trick is using separate dataset for each layer.

    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 am plotting two lines using plot(x, y, type = l, color = red)
When plotting a function using Plot, I would like to obtain the set of
Is there an equivalent method for plotting functions using ggplot to the curve() command
In ggplot I can add a series to a plot with: ggplot(diamonds, aes(x =
I am plotting a continuous variable against a factor using plot() in R (see
When plotting in R using ggplot, I've noticed that sometimes if you don't specify
I'm plotting a group of curves, using facet in ggplot2. I'd like to have
I am plotting a financial candlestick chart using this MATLAB function: http://www.mathworks.com/help/toolbox/finance/candlefts.html How do
I spend most of my time plotting data, but unfortunately I haven't found a
On a recent Java project, we needed a free Java based real-time data plotting

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.