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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:09:02+00:00 2026-05-27T04:09:02+00:00

I am trying to graph the following data: to_graph <- structure(list(Teacher = c(BS, BS,

  • 0

I am trying to graph the following data:

to_graph <- structure(list(Teacher = c("BS", "BS", "FA"
), Level = structure(c(2L, 1L, 1L), .Label = c("BE", "AE", "ME", 
"EE"), class = "factor"), Count = c(2L, 25L, 28L)), .Names = c("Teacher", 
"Level", "Count"), row.names = c(NA, 3L), class = "data.frame")

and want to add labels in the middle of each piece of the bars that are the percentage for that piece. Based on this post, I came up with:

ggplot(data=to_graph, aes(x=Teacher, y=Count, fill=Level), ordered=TRUE) + 
    geom_bar(aes(fill = Level), position = 'fill') + 
    opts(axis.text.x=theme_text(angle=45)) + 
    scale_y_continuous("",formatter="percent") + 
    opts(title = "Score Distribution") + 
    scale_fill_manual(values = c("#FF0000", "#FFFF00","#00CC00", "#0000FF")) + 
    geom_text(aes(label = Count), size = 3, hjust = 0.5, vjust = 3, position = "stack")

But it

  1. Doesn’t have any effect on the graph
  2. Probably doesn’t display the percentage if it did (although I’m not entirely sure of this point)

Any help is greatly appreciated. Thanks!

  • 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-27T04:09:03+00:00Added an answer on May 27, 2026 at 4:09 am

    The y-coordinate of the text is the actual count (2, 25 or 28), whereas the y-coordinates in the plot panel range from 0 to 1, so the text is being printed off the top.

    Calculate the fraction of counts using ddply (or tapply or whatever).

    graph_avgs <- ddply(
      to_graph, 
      .(Teacher), 
      summarise, 
      Count.Fraction = Count / sum(Count)
    )
    
    to_graph <- cbind(to_graph, graph_avgs$Count.Fraction)
    

    A simplified version of your plot. I haven’t bothered to play about with factor orders so the numbers match up to the bars yet.

    ggplot(to_graph, aes(Teacher), ordered = TRUE) + 
      geom_bar(aes(y = Count, fill = Level), position = 'fill') + 
      scale_fill_manual(values = c("#FF0000", "#FFFF00","#00CC00", "#0000FF")) + 
      geom_text(
        aes(y = graph_avgs$Count.Fraction, label = graph_avgs$Count.Fraction),  
        size = 3
      )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directed graph data structure, where I am trying to implement individual
I am trying to process the following URL via the HttpGet() method: https://graph.facebook.com/search?q=Cafe++Bakery&type=event&access_token=&type=event&access_token=239090718395|lqqOnRWlcJOb3QGp3G4HW2aqhlc .
I'm trying to retrieve some data from the FaceBook graph API. The API URL
Given the following models: class Graph(models.Model): owner = models.ForeignKey(User) def __unicode__(self): return u'%d' %
I'm trying to make a constructor for a graph class that accepts a string
I am trying to use Google graph API (image) to show some data in
I am trying create a data.frame from which to create a graph. I have
I'm trying to pull the content from the following Facebook page: https://graph.facebook.com/100000123344690/feed I'm already
I have following classes and db schema. I am trying to query this data
I am trying to create a highchart line graph using data from a .csv

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.