0

I am trying to change the y axis (Proportion) of the right histogram into decimal places like the left histogram using ggplot. I tried using geom_histogram(aes(y=..ncount..) but the bars end up squashed. Any other suggestions?

Help desperately needed!

Thanksss

Code

Histograms

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
Sammi
  • 1
  • 1
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Do not post images of code or data. We cannot copy/paste images into R for testing. – MrFlick Mar 23 '22 at 03:18

1 Answers1

0

I will give you an example using the mtcars dataset. To change the y-axis decimals to what you want, you should use the scales package which has the function number_format. If you run the following command number_format(accuracy = 0.1) in the labels of scale_y_continuous you will get the right decimals. You can use the following code as an example:

library(tidyverse)
library(scales)
mtcars %>%
  ggplot(aes(x = mpg)) +
  geom_histogram(aes(y=..count../sum(..count..))) +
  ylab("Proportion") +
  scale_y_continuous(
    labels = scales::number_format(accuracy = 0.1))

Output:

enter image description here

As you can see, the decimals for the y-axis are in the right format.

Quinten
  • 35,235
  • 5
  • 20
  • 53