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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:40:20+00:00 2026-05-25T06:40:20+00:00

There is a worked example that shows how to label a straight line in

  • 0

There is a worked example that shows how to label a straight line in R using ggplot2. Please look at example 5 – “Recreate the following plot of flight volume by longitude”.

How do you code if the x axis was categorical instead of continuous? How would one write the part of the syntax in geom_text that is currently

data = data.frame(x = - 119, y = 0) 

I created a line

 + geom_text(aes(x,y, label = "seronegative"), 
             data = data.frame(x = 1, y = 20), 
             size = 4, hjust = 0, vjust = 0, angle = 0)

and I tried several options

data = data.frame(x = 1, y = 20)
data = data.frame(x = factor(1), y = 20)
#where gard is the name of one of the categories
data = data.frame(x = "gard", y = 20) 

…but I get the error

invalid argument to unary operator

  • 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-25T06:40:21+00:00Added an answer on May 25, 2026 at 6:40 am

    It’s not entirely clear to me what you’re trying to do, since you say you try to create a line, and then your code uses geom_text. Assuming that you’d like to place a vertical line, with a text label oriented vertically on that line, using a categorical x variable, here’s a simple example:

    dat <- data.frame(x = letters[1:5],y = 1:5)
    txt <- data.frame(x = 1.5, y = 1, lab = "label")
    
    ggplot(dat,aes(x = x, y = y)) + 
        geom_point() + 
        geom_vline(xintercept = 1.5) + 
        geom_text(data = txt,aes(label = lab),angle = 90, hjust = 0, vjust = 0)
    

    which on my machine produces this output:

    enter image description here

    Note that I put the text labels in a separate data frame, outside the ggplot call. That is not be strictly necessary, but I prefer it as I find that it avoids confusion.

    Using an x value of 1.5 for the text label works here, as would setting it to “a” if you wanted it directly on the plotted x values.

    The error you’re describing suggests to me a simple syntax error somewhere in your code (which you haven’t completely provided). Perhaps this example will help you to spot it.

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

Sidebar

Related Questions

I worked on a project that had the following requirement: TableA is the parent
Are there any alternatives to JSTL? One company I worked for 3 years ago
Recently I was talking to a co-worker about C++ and lamented that there was
There is a conversion process that is needed when migrating Visual Studio 2005 web
I've got a very old php application (1999) that has been worked on during
Using Reporting Services in SQL Server 2005: Is there a way to count only
I am getting following error: COM object that has been separated from its underlying
Is there a way to use a wildcard in a javascript bookmarklet? For example,
I've worked with a few of these in the past, but I'm looking for
Short of inserting a try/catch block in each worker thread method, is there a

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.