0

I have a dataframe that collects the % of incidents according to whether they are of a certain type at different times of observation.

Day  %
1    2
2    17
3    11
4    32
5    21
6    47

I would like to show the bars with the weight of the percentage, but instead of the maximum being the highest value, I would like all of them to be shown with a 100% scale as the maximum value. So that their length is proportional to the % they represent, for example 50% being a bar of half the total length possible. But I don't know how to do it

It would be the same solution if I added a new row with a 100% incidence rate and therefore a new column in the graph, but I want to avoid that so as not to confuse the recipient of the report

Meissen
  • 27
  • 3
  • Is this the kind of thing you're looking for? https://stackoverflow.com/questions/9563368/create-stacked-barplot-where-each-stack-is-scaled-to-sum-to-100 – Dubukay Oct 27 '20 at 16:25

1 Answers1

1

like this?

library( data.table )
library( ggplot2 )
library( scales )
DT <- fread("Day  %
1    2
2    17
3    11
4    32
5    21
6    47")

ggplot( data = DT, aes( x = Day, y = `%`/100 ) ) + 
  geom_col() +
  coord_cartesian( ylim = c(0,1) ) +
  scale_y_continuous( labels = scales::percent ) +
  labs( y = "percentage" )
  

enter image description here

Wimpel
  • 26,031
  • 1
  • 20
  • 37