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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:23:21+00:00 2026-06-05T10:23:21+00:00

While adding annotation text to a plot I noticed that geom_text() produced unsightly, jagged

  • 0

While adding annotation text to a plot I noticed that geom_text() produced unsightly, jagged text, while annotate() produced smooth, nice-looking text. Does anyone know why this happens and if there’s any way to fix it? I know I could just use annotate() here, but there are probably cases where geom_text() is preferable, and I’d like to find a fix. Also, geom_text() can’t be intended to give poor-looking text, so either I’m doing something wrong, or I’ve run into some sort of subtle side effect.

Here’s some fake data and the code to produce the graph, plus an image showing the results.

library(ggplot2)
age = structure(list(age = c(41L, 40L, 43L, 44L, 40L, 42L, 44L, 45L, 
        44L, 41L, 43L, 40L, 43L, 43L, 40L, 42L, 43L, 44L, 43L, 41L)), 
        .Names = "age", row.names = c(NA, -20L), class = "data.frame")
ggplot(age, aes(age)) + 
  geom_histogram() +
  scale_x_continuous(breaks=seq(40,45,1)) +
  stat_bin(binwidth=1, color="black", fill="blue") +
  geom_text(aes(41, 5.2, 
            label=paste("Average = ", round(mean(age),1))), size=12) +
  annotate("text", x=41, y=4.5, 
           label=paste("Average = ", round(mean(age$age),1)), size=12)

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-05T10:23:23+00:00Added an answer on June 5, 2026 at 10:23 am

    geom_text, despite not using anything directly from the age data.frame, is still using it for its data source. Therefore, it is putting 20 copies of “Average=42.3” on the plot, one for each row. It is that multiple overwriting that makes it look so bad. geom_text is designed to put text on a plot where the information comes from a data.frame (which it is given, either directly or indirectly in the original ggplot call). annotate is designed for simple one-off additions like you have (it creates a geom_text, taking care of the data source).

    If you really want to use geom_text(), just reset the data source:

    ggplot(age, aes(age)) + 
      scale_x_continuous(breaks=seq(40,45,1)) +
      stat_bin(binwidth=1, color="black", fill="blue") +
      geom_text(aes(41, 5.2, 
                label=paste("Average = ", round(mean(age$age),1))), size=12,
                data = data.frame()) +
      annotate("text", x=41, y=4.5, 
               label=paste("Average = ", round(mean(age$age),1)), size=12)
    

    enter image description here

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

Sidebar

Related Questions

While adding the lines of a text file to List , i donot want
While adding text in a textarea, I dont want to allow '*' after '&'.
I just noticed, while adding a new item to Solution Explorer, a Report item
I've noticed a strange behaviour with RaisePropertyChanged while adding objects to a ViewModel property.
In jqGrid, is it possible to define a cell's Title (hover) text while adding
While adding two language code files i.e. C# and VB.NET to App_Code, got an
I can't view header in JTable while adding it into a JFrame.. String[] col={Name,ID,Marks};
I am getting the following exception while adding data into database: org.hibernate.HibernateException: The database
Is there any way to add bouncy effect while adding marker on map in
i have two list, i wanted to update the second list while adding 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.