我想绘制每小时访问我网站的某个网页。 x轴显示小时(0到23),y轴显示唯一访问次数。
我在plot()
中压制轴并将其添加到axis()
。我只想要标记为最低和最高的y值:
axis(2,
at = seq(min(...), max(...), 1),
labels = c(min(...),
rep.int("", max(...) - min(...) - 1),
max(...)
)
)
(代码示例中的省略号表示列。我将其留下来以便更清晰地了解代码结构。)
但在图中,最高值的标签不会出现:
有时候(取决于值的范围)我可以通过将rep.int("" ...
更改为rep.int(" "
来获得最高值标签,即用空格标记刻度,但这不起作用总是
为什么R不打印最高标签?而且,更重要的是:
如何强制R打印最高标签?
完整的代码示例:
sitzungen <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 8, 4, 0, 8, 3, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 2, 0, 0, 2, 0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 2, 2, 1, 0, 0, 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 4, 1, 2, 1, 7, 7, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 3, 8, 4, 1, 2, 0, 1, 1, 0, 0, 5, 0, 3, 3, 2, 3, 1, 2, 0, 1, 2, 0, 0, 0, 1, 0, 1, 2, 3, 0, 0, 3, 1, 6, 3, 9, 1, 0, 2, 1, 4, 8, 2, 2, 2, 0, 0, 0, 2, 1, 3, 1, 1, 2, 1, 2, 3, 1, 4, 3, 0, 2, 3, 1, 3, 1, 5, 2, 0, 0, 1, 0, 1, 2, 1, 0, 3, 0, 1, 0, 3, 7, 2, 2, 1, 2, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 15, 2, 2, 1, 0, 0, 0, 0, 0, 2, 3, 0, 3, 0, 2, 1, 1, 2, 2, 4, 2, 1, 4, 2, 1, 2, 2, 1, 0, 0, 0, 7, 0, 2, 4, 2, 0, 2, 3, 5, 2, 1, 4, 4, 2, 0, 2, 4, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 2, 1, 2, 1, 1, 2, 1, 4, 1, 1, 1, 0, 0, 3, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
stunde <- rep(0:23, 20)
stuendlich <- data.frame(cbind(stunde, sitzungen))
aggr <- aggregate(sitzungen ~ stunde, stuendlich, sum)
aggr <- rbind(aggr, c(24, aggr[which(aggr$stunde == "23"),]$sitzungen))
plot(aggr, type = "s", xlim = c(0, 24), axes = FALSE, xlab = "Stunde", ylab = "Sitzungen", main = "Sitzungen pro Stunde (kumuliert)")
axis(1, at = seq(0.5, 23.5, 1), labels = 0:23)
axis(2, at = seq(min(aggr$sitzungen), max(aggr$sitzungen), 1), labels = c(min(aggr$sitzungen), rep.int(" ", max(aggr$sitzungen) - min(aggr$sitzungen) - 1), max(aggr$sitzungen)))