0

is it possible to increase the absolute frequency of my intervals, here I mean eg as in the program for level: [0,1) count(frequency ) 1 , but I want to set it count to eg 780,000. for each interval I want to increase the frequency with different values.

or maybe there is another way of dealing with the tasks.

I look forward to feedback.

VG

age<-c(0:113)  
d <- cut(age, breaks = c (0,1,6,15,18,21,25,40,60,65,113),
          include.lowest = TRUE, right= FALSE) 
w <- table(d)  
hist(w)

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
Nganja
  • 9
  • 1

1 Answers1

0

You can store the histogram as a variable, then overwrite its counts with whatever numbers you want:

hw <- hist(w, plot = FALSE)
hw$counts <- c(780000, 500000, 0, 0, 200000)

You can now plot it using plot:

plot(hw, col = 'gray', yaxt = 'none', ylim = c(0, 1e6))
axis(2, labels = scales::comma(c(0, 500000, 1000000)), 
     at = c(0, 500000, 1000000))

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Hey @Allan ,thanks so much for the reply.but I still have a question: if I want to plot against density(relative frequency) what can I do ? I try using hw<- hist(table(d) , plot = FALSE , Freq= FALSE ) but the argument Freq=False is not been run and also what if I want to change my intervals names.For example the bar from 0-10 as [0,1) and from 10-20 as [1,6) etc. – Nganja May 20 '22 at 17:03
  • @Nganja If you want all the counts to be the correct relative size you can just do `hw$count <- hw$count * 1000` (or whatever number you want instead of 1000). If you want to change the x axis, just draw one on using `axis` the way I showed with the y axis. – Allan Cameron May 20 '22 at 18:26