R中两个离散序列的直方图

时间:2016-11-21 13:10:24

标签: r plot format histogram plotrix

我在R中有两个不同长度的向量,它只包含整数(1,2,3,4,5)。我想逐个绘制它们的直方图(百分比,而不是计数)。

我尝试在multhist包中使用plotrix,但有两个问题:

  1. 它以y-axis作为计数,而不是百分比。

  2. 它以x-axis作为浮动数字绘制,例如1.1,1.5等,而显然我只需要在{1,2},1,2,4,4,5处绘制x-axis

  3. 我怎么能在R?中做到这一点?

    非常感谢,

    更新

    代码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)
    

    ``

1 个答案:

答案 0 :(得分:2)

试试这个:

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

enter image description here