每个频率值均带有条形的直方图 [英] A histogram with a bar for each frequency value

查看:55
本文介绍了每个频率值均带有条形的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个骰子100卷的数据,可以取11个值-> {2,3,4,5,6,7,8,9,10,11,12}

I have a data of 100 rolls of two dice, which can take on 11 values -> {2,3,4,5,6,7,8,9,10,11,12}

如何在R中创建直方图,以显示所有11个直方图,每个直方图都是自己的条形,每个直方图都有一个标签.

How do I create a histogram in R that would show all 11 of them, each as it's own bar with a label for each one of them.

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小节.

我做了一些近似的移动中断,如下所示:

I did something approximate with moving breaks 0.5 up like so:

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)

推荐答案

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

Histograms can also be plotted with ggplot. Using @flodel's data:

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

这篇关于每个频率值均带有条形的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆