我想知道如何将直方图(请参阅下面的h = hist()
)更改为折线图,如下图所示?
这是我尝试过的(没有成功):
set.seed(0)
hyp = rhyper(1e3, 12, 5, 7)
h = hist(hyp, plot = FALSE)
plot(hyp, xlim = range(hyp), ylim = range(h$counts), type = "h", lwd = 2)
table(hyp)
# > hyp
# > 2 3 4 5 6 7 # X-axis
# > 2 66 253 404 240 35 # Y-axis
答案 0 :(得分:2)
只需运行table
,然后绘制
with(data.frame(table(hyp)), plot(x = as.numeric(as.character(hyp)), y = Freq, type = "h"))
或以下似乎也有效
plot(table(hyp))