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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:15:19+00:00 2026-06-15T23:15:19+00:00

This is an extension question to: How to put labels over geom_bar for each

  • 0

This is an extension question to: How to put labels over geom_bar for each bar in R with ggplot2

My data has some negatives and so the labels intrude into the bar. How can I adjust this? I need the label placements to be read dynamically.

Thanks!

growth<-data.frame(ElapsedTimeMonths=c(3,6,12,24),MedianGrowth=c(-0.011,-0.002,0.014,0.052))
g<-ggplot(growth, aes(x=factor(ElapsedTimeMonths),y=MedianGrowth))
g<-g+geom_bar(position="dodge", stat="identity")
g<-g+scale_y_continuous(labels = percent)
g<-g+geom_text(aes(label=as.character(100*MedianGrowth)), position=position_dodge(width=0.9), vjust=-0.25)
g

enter image description here

  • 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-15T23:15:20+00:00Added an answer on June 15, 2026 at 11:15 pm

    Graphical parameter settings can be vectors so that different
    shapes (geom text here)can have different appearances.

    You need to give vjust as a vector, with opposite sign of MedianGrowth

    Your data

    growth <- data.frame(ElapsedTimeMonths=c(3,6,12,24),
                       MedianGrowth=c(-0.011,-0.002,0.014,0.052),
                      )
    

    I create the vjust vector

     vvjust <- rep(1, length(growth$MedianGrowth))
     vvjust[growth$MedianGrowth > 0 ] <- -0.25
     [1]  1.00  1.00 -0.25 -0.25
    

    Then I plot

    g<- ggplot(growth, aes(x=factor(ElapsedTimeMonths),y=MedianGrowth))
    g<- g+ geom_bar(stat='identity',position='dodge')
    g<- g+ scale_y_continuous(labels = percent)
    g<- g+ geom_text(aes(label=as.character(100*MedianGrowth)), 
                     position=position_dodge(width=0.9), vjust=vvjust)
    

    enter image description here

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

Sidebar

Related Questions

This is an extension to a question which I asked some time ago. I
my first question is, where do I put this custom extension so that it
(Note: This is an extension of a previous question .) I am having some
This is an extension of question: Order of the initialization in Java so in
This is an extension of the question I asked here I have a relationship
This is an extension of a question I previously asked here . Long story
This is an extension for this question asked an hour ago. We cannot modify
This is an extension of this question and probably might even be a duplicate
This is an extension to the question I asked here: Get text from clipboard
This is an extension of this question: SQLite problem selecting two columns as one

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.