2014-10-02 39 views
0

我有两个骰子100卷的数据,它可以取11个值 - > {2,3,4,5,6,7,8,9,10, 11,12}每个频率值带有一个条的直方图

如何在R中创建一个直方图来显示它们中的全部11个,每个直方图都是它自己的酒吧,每个酒吧都有一个标签。

hist(data$X1,breaks=c(1,2,3,4,5,6,7,8,9,10,11,12,13),col = "lightblue",xlab="Sum of a roll") 

只给出10个小节。

编辑:

我做了大致与移动减免0.5像这样:

breaks=c(1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5,12.5,13.5) 
+0

还有呢?什么让你的新休息?它回答你的问题吗? – 2014-10-02 03:19:39

+0

直方图用于连续随机变量(并且您的示例是离散的)。像这样的'barplot()'可能更合适。 – MrFlick 2014-10-02 04:28:01

回答

0

直方图也可以用ggplot绘制。使用@ flodel的数据:

dd = data.frame(table(sums)) 
ggplot(dd)+geom_bar(aes(x=sums, y=Freq), stat='identity') 

enter image description here

3

你可能只是这样做的频率表的barplot:

num.dices <- 2L 
num.rolls <- 100000L 
outcomes <- matrix(sample(1:6, num.dices * num.rolls, replace = TRUE), 
        nrow = num.rolls, ncol = num.dices) 
sums <- rowSums(outcomes) 
barplot(table(sums)) 

enter image description here

相关问题