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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:40:10+00:00 2026-06-14T00:40:10+00:00

I have a ggplot where I have used expression(phantom(x) >=80) in the label text

  • 0

I have a ggplot where I have used expression(phantom(x) >=80) in the label text to get a proper greater-than-or-equal symbol.

However I also need to have (N=…) immediately underneath:

require(ggplot2)
.d <- data.frame(a = letters[1:6], y = 1:6)

labs <- c("0-9\n(N=10)","10-29\n(N=10)","30-49\n(N=10)", +
   "50-64\n(N=10)","65-79\n(N=10)", expression(phantom(x) >=80))

ggplot(.d, aes(x=a,y=y)) + geom_point() + 
   scale_x_discrete(labels = labs)

enter image description here

How can I combine the expression() with the escape \n ?

  • 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-14T00:40:11+00:00Added an answer on June 14, 2026 at 12:40 am

    As @otsaw said in his answer to your earlier question, plotmath (and therefore expression) doesn’t allow linebreaks.
    However, as a hack, you can use atop to let ≥80 appears on top of (N=10). But as you will soon see it doesn’t match with the other labels:

    labs <- c("0-9\n(N=10)","10-29\n(N=10)","30-49\n(N=10)", 
              "50-64\n(N=10)","65-79\n(N=10)", 
              expression(atop(phantom(x) >=80, (N==10))))
    

    enter image description here

    So, as a further hack, you can pass the other labels as expressions:

    labs <- c(expression(atop(0-9,(N==10))),expression(atop(10-29,(N==10))),
              expression(atop(30-49,(N==10))), expression(atop(50-64,(N==10))),
              expression(atop(65-79,(N==10))), expression(atop(phantom(x) >=80, (N==10))))
    

    enter image description here

    But of course you have @otsaw solution (using Unicode) that is considerably less wordy:

    labs <- c("0-9\n(N=10)","10-29\n(N=10)","30-49\n(N=10)", 
              "50-64\n(N=10)","65-79\n(N=10)", 
              "\u2265 80\n(N=10)")
    

    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 have issued the following command to a ggplot figure: facet_wrap(~variable,scales=free) but I also
Another ggplot legend question! I have a dataset of the form test <- data.frame(
I have this ggplot: ggplot(dt.m, aes(x=pct.on.OAC.cont,y=Number.of.Practices, fill=Age.Group)) + geom_bar(stat=identity,position=position_dodge()) + geom_smooth(aes(x=pct.on.OAC.cont,y=Number.of.Practices, colour=Age.Group), se=F) How
I have a short routine which arranges ggplot and grid graphics using the grid.arrange
I have used ggplot2 to create the image below. I want to explore viewing
I have this ggplot ggplot(dt.1, aes(x=pctOAC,y=NoP, fill=Age)) + geom_bar(stat=identity,position=position_dodge()) + geom_smooth(aes(x=pctOAC,y=NoP, colour=Age), se=F, method=loess,show_guide
I have a series of ggplot graphs that I'm repeating with a few small
How can I add text to points rendered with geom_jittered to label them? geom_text
I want to make a radial stacked barchart. I have something like this: ggplot(diamonds,
I have the following part of a data frame which is much bigger than

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.