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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:08:49+00:00 2026-06-01T06:08:49+00:00

The graph I’m currently trying to make falls a little between two stools. I

  • 0

The graph I’m currently trying to make falls a little between two stools. I want to make a histogram that is composed of stacked and labelled boxes. Here’s an example of exactly the sort of thing I’m talking about, taken from a recent article in the New York Times:

http://farm8.staticflickr.com/7109/7026409819_1d2aaacd0a.jpg

Is it possible to achieve this using ggplot2?

To amplify the question somewhat, so far what I have is:

dfr <- data.frame(
name = LETTERS[1:26],
percent = rnorm(26, mean=15)
)

ggplot(dfr, aes(x=percent, fill=name)) + geom_bar() +
stat_bin(geom="text", aes(label=name))

…which I’m clearly doing all wrong. Ultimately what I’d ideally like is something along the lines of the manually-modified graph below, with (say) letters A to M filled one shade and N to Z filled another.

http://farm8.staticflickr.com/7116/7026536711_4df9a1aa12.jpg

  • 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-01T06:08:50+00:00Added an answer on June 1, 2026 at 6:08 am

    Here you go!

    set.seed(3421)
    # added type to mimick which candidate is supported
    dfr <- data.frame(
      name    = LETTERS[1:26],
      percent = rnorm(26, mean=15),
      type    = sample(c("A", "B"), 26, replace = TRUE)
    )
    
    # easier to prepare data in advance. uses two ideas
    # 1. calculate histogram bins (quite flexible)
    # 2. calculate frequencies and label positions
    dfr <- transform(dfr, perc_bin = cut(percent, 5))
    dfr <- ddply(dfr, .(perc_bin), mutate, 
      freq = length(name), pos = cumsum(freq) - 0.5*freq)
    
    # start plotting. key steps are
    # 1. plot bars, filled by type and grouped by name
    # 2. plot labels using name at position pos
    # 3. get rid of grid, border, background, y axis text and lables
    ggplot(dfr, aes(x = perc_bin)) +
      geom_bar(aes(y = freq, group = name, fill = type), colour = 'gray', 
        show_guide = F) +
      geom_text(aes(y = pos, label = name), colour = 'white') +
        scale_fill_manual(values = c('red', 'orange')) +
        theme_bw() + xlab("") + ylab("") +
        opts(panel.grid.major = theme_blank(), panel.grid.minor = theme_blank(),
          axis.ticks = theme_blank(), panel.border = theme_blank(), 
          axis.text.y = theme_blank())
    

    enter image description here

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

Sidebar

Related Questions

https://graph.facebook.com/ I need to make an HTTPS request to that. And then get the
I drew a little graph in paint that explains my problem: But it doesn't
We have social graph that is later broken to clusters of high cohesion. Something
I have an object graph that contains objects that are (for purposes of this
I have a complex graph of XML-serializable classes that I'm able to (de)serialize to
In graph theory, what is the distinction between minimal distance (which Dijkstra's algorithm finds),
The Graph API is currently not allowing me to grab the wall feed of
What is the best Graph/Charts Solution for PHP that is Interactive (at least anchor
I have this object graph, I want to map: abstract Account (username, password, ...)
When Traversing a Tree/Graph what is the difference between Breadth First and Depth first?

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.