Asi
Asi

Reputation: 1

Y axis proportions in histogram with ggplot

I have prepared a dataset that I wish to display as a histogram.

I believe I get the X axis right, but can't seem to get totmis1 on the Y axis... Just an unclear histogram:

ggplot(data = brfss2013a, aes(x = totmis)) + 
  geom_histogram(binwidth = 3)

enter image description here

Upvotes: 0

Views: 50

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226182

tl;dr use geom_bar(stat="identity") instead of geom_histogram()

I think the terminology you are looking for is a bar chart (technically, a histogram is the result of counting/binning a continuous distribution of data; it's not clear whether you've already computed these values by binning, or whether the data mean something else, but I don't think it matters).

dd <- data.frame(totmis=1:11,
                 totmis1=c(5786,5086,3187,2594,1591,1318,
                           847,754,512,511,383))
library(ggplot2)
ggplot(dd, aes(totmis,totmis1))+
    geom_bar(stat="identity")

You need stat="identity" because geom_bar() tries to count occurrences by default ...

enter image description here

Upvotes: 2

Related Questions