Reputation: 7517
I was wondering how I could change the histogram (see h = hist()
below) to a line-chart as shown in the picture below?
Here is what I tried (with no success):
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
Upvotes: 0
Views: 110
Reputation: 32558
Just run the table
and then plot
with(data.frame(table(hyp)), plot(x = as.numeric(as.character(hyp)), y = Freq, type = "h"))
OR following seems to work too
plot(table(hyp))
Upvotes: 2