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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:31:52+00:00 2026-06-10T06:31:52+00:00

I have a basic problem with the geom_histogram function With the dataset: df <-

  • 0

I have a basic problem with the geom_histogram function

With the dataset:

df <- data.frame(value = factor( rep(c("A","B"), c(100,200) )))

I create a histogram with:

ggplot(df, aes(x=value, fill = factor(value))) + geom_histogram()

and the output is a histogram with count 100 for A and 200 for B

If I instead plot the density with:

ggplot(df, aes(x=value, fill = factor(value), ..density..)) + geom_histogram()

the output is a histogram with density 1 for A and 1 for B. I assume the reason is that the density is calculated on A and B separately.

The histogram created with:

ggplot(df, aes(x=value, group = 1, fill = factor(value),..density..)) + geom_histogram()

Is a histogram where A is 0.33 and B is 0.66, but the fill color is black, and I cannot find a way to get the fill colors used in the previous histograms in this version of the plot.

How do I generate the last version of the histogram with fill colors based on factor(value)?

  • 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-10T06:31:54+00:00Added an answer on June 10, 2026 at 6:31 am

    I solved the problem with:

    ggplot(df, aes(x=value, fill = factor(value))) + 
     geom_histogram(aes(y=..count../sum(..count..)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic problem with an object. I create the object in
I have a probably very basic problem with PIL's crop function: The cropped image's
I think i have a basic problem in understanding the dojo toolkit. Well I
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have a pretty basic problem but I can't seem to figure it out...
So I have a rather basic javascript problem which I have been slamming my
I have a very basic texture map problem in GL on iPhone, and I'm
Hi I have run into a very weird problem. I have a basic chrome
I have a kind of basic (but still unresolved) problem. I'm building a program
I have a problem with AvalancheImagineBundle for Symfony 2 I followed the basic instructions

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.