Yang Mei Lian
Yang Mei Lian

Reputation: 75

Histogram of two discrete series one by one in R

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)

``

Upvotes: 0

Views: 216

Answers (1)

Sandipan Dey
Sandipan Dey

Reputation: 23101

Try this:

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

enter image description here

Upvotes: 2

Related Questions