gpt4 book ai didi

r - 如何在hist()图中设置xlim,同时在直方图中显示变量的整个范围

转载 作者:行者123 更新时间:2023-12-04 22:47:14 25 4
gpt4 key购买 nike

这是我在R中所做的直方图,请在此处查看:

这是我用来获取它的代码:

par(mfrow = c(3, 1))
hist(outcome[, 11], main = "Heart Attack", xlim = c(10,20), xlab = "30-day Death Rate")
hist(outcome[, 17], main = "Heart failure", xlim = c(10, 20), xlab = "30-day Death Rate")
hist(outcome[, 23], main = "Pneumonia", xlim = c(10,20), xlab = "30-day Death Rate")

因此,如何修改代码以获取下图,请参见此处:

我需要在直方图中显示数据的全部范围,同时将x轴的范围从10-20限制在中间,中间只有15

最佳答案

这段未经测试的代码:

par(mfrow = c(3, 1)) #partition the graphics device, 3 stacked
# calculated a common max and min to allow horizontal alignment
# then make 3 histograms (that code seems pretty self-explanatory)
xrange <- range( c(outcome[, 11],outcome[, 17],outcome[, 23]) )
hist(outcome[, 11], main = "Heart Attack", xlim = xrange,xaxt="n",
xlab = "30-day Death Rate")
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10) )
hist(outcome[, 17], main = "Heart failure", xlim = xrange,xaxt="n",
xlab = "30-day Death Rate")
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10) )
hist(outcome[, 23], main = "Pneumonia", xlim = xrange, xaxt="n",
xlab = "30-day Death Rate")
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10) )

关于r - 如何在hist()图中设置xlim,同时在直方图中显示变量的整个范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com