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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:11:00+00:00 2026-05-22T16:11:00+00:00

I’ve discovered what I think is a bug in ggplot2’s use of geom_text and

  • 0

I’ve discovered what I think is a bug in ggplot2’s use of geom_text and am wondering if anyone out there has a work-around/is able to point out what I’m doing wrong.

Consider the following sample code:

library(ggplot2)

Treatment <- rep(c('C','T'),3)
Group <- rep(c('A','B','C'),each=2)
Response <- c(0.22894321, 0.23391813, 0.92256514, 0.92705167, 0.05982670, 0.09667674)
Differences <- c('+0pts',  '+0pts', '+0pts', '+0pts', '+4pts', '+4pts')

df <- data.frame(Treatment, Group, Response, Differences)

ydef <- c(0.03, 0.03, 0.2)

hist <- ggplot(df, aes(x=Group, y=Response, fill=Treatment, stat="identity"))
hist + geom_bar(position = "dodge")  + geom_text(aes(label = Differences,y=ydef))

If this works for you the same way that it does for me–using the most current versions of ggplot2 and R 2.12.2–groups B and C should have two text floats each, spaced equal distances apart. Obviously this is not what we want. Now change ‘ydef’ such that

ydef <- c(0.03, 0.03, 0.03)

re-run the script above, and the problem is solved–each group now only has one text float corresponding to differences (or rather two, layered exactly on top of each other). How does this make any sense? I’ve been using this basic structure in a fairly large scale application, and have not had any trouble until I got to this specific example with these specific numbers.

Part of the problem may be the way I’m constructing ‘Differences’, by adding it as a column to the data frame and placing this text on the chart with geom_text. If there was a way to do the same thing using a vector with only three character entries I’m sure that would solve the problem.

In short (1) help please! and (2) here is a potentially interesting bug for the consideration of the ggplot2 community.

Cheers,
Aaron

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

    I don’t think this is a bug, I think you’re not using aes() properly. The aesthetics set in aes() ought to refer to a variable in a data frame. Your data frame (for which some here may chide you for naming ‘df’) doesn’t have a variable named ydef in it. If you add it to your data frame, it works just fine for me:

    df$ydef <- rep(ydef,each=2)
    

    Note that the values need to be repeated in accordance with the levels of Group.

    If you’re going to set an aesthetic to a single value not contained in a data frame passed to the geom, it should be just that, a single value, and it should happen outside the aes() call.

    EDIT: To explain the behavior you’re seeing, you’re passing a vector of length 3 to ggplot, which then tries to reconcile it with a data frame with 6 rows. So R recycles the vector, leading to this situation:

    A 0.03
    A 0.03
    B 0.2
    B 0.03
    C 0.03
    C 0.2
    

    So now you have two levels with two distinct values associated with them.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.