题目2: 如何绘制对数坐标的直方图?
# 准备数据 set.seed(1) mydata <- rnorm(100)
N 版
myhist <- hist(mydata, plot = FALSE) plot(myhist$mids, myhist$counts, log = "y", type = 'h')
# or myhist_log <- myhist myhist_log$counts <- log10(myhist_log$counts) plot(myhist_log, ylab = 'log(Frequency)')
T 版
library(ggplot2) ggplot() + geom_histogram( aes(mydata), breaks = seq(-2, 2, 0.5)) + scale_y_log10()
贡献者为 @tranquil @dapengde @Heterogeneity 等,来自 https://d.cosx.org/d/420798。↩