[R] Including percentage values inside columns of a histogram

Paul Bernal p@u|bern@|07 @end|ng |rom gm@||@com
Mon Aug 16 23:54:48 CEST 2021


Hello everyone,

I am currently working with R version 4.1.0 and I am trying to include
(inside the columns of the histogram), the percentage distribution and I
want to generate three histograms, one for each fiscal year (in the Date
column, there are three fiscal year AF 2017, AF 2020 and AF 2021). However,
I can´t seem to accomplish this.

Here is my data:

structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("AF 2017", "AF 2020", "AF 2021"), class =
"factor"),
    Amount = c(40100, 101100, 35000, 40100, 15000, 45100, 40200,
    15000, 35000, 35100, 20300, 40100, 15000, 67100, 17100, 15000,
    15000, 50100, 35100, 15000, 15000, 15000, 15000, 15000, 15000,
    15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000, 15000,
    15000, 15000, 20100, 15000, 15000, 15000, 15000, 15000, 15000,
    16600, 15000, 15000, 15700, 15000, 15000, 15000, 15000, 15000,
    15000, 15000, 15000, 15000, 20200, 21400, 25100, 15000, 15000,
    15000, 15000, 15000, 15000, 25600, 15000, 15000, 15000, 15000,
    15000, 15000, 15000, 15000)), row.names = c(NA, -74L), class =
"data.frame")

I would like to modify the following script:

> with(datasetregs, Hist(Amount, groups=Date, scale="frequency",
+   breaks="Sturges", col="darkgray"))

#The only thing missing here are the percentages corresponding to each bin
(I would like to see the percentages inside each column, or on top outside
if possible)

Any help will be greatly appreciated.

Best regards,

Paul.

	[[alternative HTML version deleted]]



More information about the R-help mailing list