我试图创建几个直方图,显示药物对心脏病发作频率的影响。
目前,R正在将我的数据组织到箱[0 - 0.5,0.5 - 1.0,1.0 - 1.5等]中,但我希望它只使用整数值:[0 - 1,1 - 2 ,2 - 3等]。
我尝试过使用xaxt =“n”参数和axis()函数。他们“工作”,但他们没有解决上述问题。我也尝试使用breaks = seq(0,5,l = 6),但这会将我的y轴从频率转换为密度。
以下是我最近两次尝试的代码:
hist(fourTrials$red_5, breaks=5, right = FALSE,
xlab = "Number of Heart Attacks",
xlim = c(0, 4), ylim = c(0,4),
main = "Experimental Group 1, n = 400", col = "light blue")
hist(fourTrials$red_5, breaks=seq(0,5,l=6), freq = F, right = FALSE,
xlab = "Number of Heart Attacks",
xlim = c(0, 4), ylim = c(0,4),
main = "Experimental Group 1, n = 400", col = "light blue",yaxs="i",xaxs="i")
感谢您的帮助!
答案 0 :(得分:0)
我相信你想要的是:
hist(fourTrials$red_5, breaks=0:4, freq = TRUE, right = FALSE,
xlab = "Number of Heart Attacks",
xlim = c(0, 4), ylim = c(0,4),
main = "Experimental Group 1, n = 400",
col = "lightblue", yaxs="i", xaxs="i")