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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:22:37+00:00 2026-05-29T15:22:37+00:00

I have the following data frame z x y 1 1 a 2 2

  • 0

I have the following data frame

z x y
1 1 a
2 2 a
3 1 a
4 2 a
5 1 b
6 9 b
7 9 b
8 8 b
9 7 b

when I do

p = ggplot(z,aes(x,group=y)) + geom_histogram(aes(y = ..density..,group=y)) +       facet_grid(y ~ .)
p

I get the faceted plots, but not with the percentages on the y-axis for each symbol within z$y.

Basically, I want a histogram chart, but with the percentages that show the frequency distribution within each value of z$y i.e. a,b.

In this case, under ‘a’, 50% is 1 and 50% is 2, and under ‘b’, 20% is 1, 40% is 9, 20% is 7 and 20% is 8. I want this charted as histograms using faceting.

  • 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-29T15:22:38+00:00Added an answer on May 29, 2026 at 3:22 pm

    That is not a histogram (there is no density estimation), but a bar chart.

    d <- data.frame( 
      value = c(1,2,1,2,1,9,9,8),
      group = c(rep("a",4),rep("b",4))
    )
    # With counts
    ggplot(d) + geom_bar(aes(factor(value))) + facet_grid(group ~ .)
    # With percentages
    ggplot(d) + 
      geom_bar(aes(factor(value), (..count..)/sum(..count..))) + 
      scale_y_continuous(formatter = 'percent') + 
      facet_grid(group ~ .)
    

    Note: In more recent versions of ggplot2 we would use scale_y_continuous(labels = percent_format()) instead, and make sure to load the scales package.

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

Sidebar

Related Questions

I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
I have the following data frame: y <- data.frame(group = letters[1:5], a = rnorm(5)
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
I have the following data.frames: a <- data.frame(id = 1:3, v1 = c('a', NA,
I have the following data: a=c(1:10) b=c(16:25) c=c(24:33) wa=c(3,7,3,3,3,3,3,3,3,1) wb=c(3,2,3,3,3,3,3,3,3,8) wc=c(4,1,4,4,4,4,4,4,4,1) z=data.frame(a,b,c,wa,wb,wc) I want
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the
I'm struggling with the following. If have a (big) data frame with the following:
I have a data.frame with the following characteristics: +-----------------------------------------+ | earning budget ts total
I have the following data frame: A B C D Xax 0.451 0.333 0.034
I have the following part of a data frame which is much bigger than

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.