我正在尝试对范围很广的数据集进行密度绘制。
data = c(-10,-20,-20,-18,-17,1000,10000,500,500,500,500,000)
积(密度(数据))
如图所示,我们看不到多少 。
有没有办法在x轴上使轴断开(或多个轴)以更好地可视化数据的分布?或者,有没有办法在几个图表中绘制特定范围的数据而不是将它们粘贴在一起?
非常感谢!
答案 0 :(得分:0)
包gap.plot()
中有一个函数plotrix
,但我认为它存在一些问题(请参阅How to plot “multiple” curves with a break through y-data-range in R?)。我建议你画两个图。
## use small margins and relatively big outer margins (to write labels).
old.par <- par(mfrow = c(1, 2), mar = rep(0.5, 4), oma = c(4, 4, 1, 1))
plot(density(data), xlim = c(-1000, 29000), main = "", bty="c") # diff 30000
abline(v = par("usr")[2], lty=2) # keep the same diff of xlim to avoid misleading
plot(density(data), xlim = c(471000, 501000), main = "", yaxt ="n", bty="]") # diff 30000
abline(v = par("usr"[1]), lty=2)
par(old.par)