0

I have two vectors with different lengths in R, which contains integer number only (1,2,3,4,5). I want to plot histogram of them (in percentage, not in count) one by one.

I tried to use multhist in the package plotrix, but there are two problems:

  1. It plots with y-axis as count, not percentage.

  2. It plots with x-axis as float number, such as 1.1, 1.5, etc. while obviously I only need to plot with x-axis at 1, 2, 3, 4, 5.

How could I do that in R?

Thank you very much,

Update:

the code with multhist:

``

x1 <- round(runif(1000, 1.0, 5.0), digits=0)    
x2 <- round(runif(100, 1.0, 5.0), digits=0)    
require (plotrix)    
multhist (x1,x2)

``

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Yang Mei Lian
  • 75
  • 1
  • 11

1 Answers1

2

Try this:

multhist(list(x1,x2),breaks=seq(0.5,5.5,by=1),probability=TRUE)

enter image description here

Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63