Reputation: 27
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
Upvotes: 0
Views: 123
Reputation: 27772
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" )
Upvotes: 1