【发布时间】:2022-12-09 22:03:35
【问题描述】:
通常,在 R 中,我可以使用 xpd = NA 将元素添加到扩展到绘图区域之外的现有绘图中。
但是,在这种情况下,我试图添加小提琴图或箱形图,但这种方法不起作用。
library(vioplot)
# generate some data
dat <- replicate(10, rnorm(20), simplify = FALSE)
range(unlist(dat))
# first example, with all data within range
plot.new()
plot.window(xlim = c(1, 10), ylim = c(-5,5))
axis(1)
axis(2)
vioplot(dat, add = TRUE, frame.plot = FALSE)
现在试图在绘图区域之外绘图。
plot.new()
par(oma = c(3,3,3,3))
plot.window(xlim = c(1, 10), ylim = c(-10, -2))
axis(1)
axis(2)
vioplot(dat, add = TRUE, frame.plot = FALSE, xpd = NA)
boxplot(dat, add = TRUE, frame.plot = FALSE, xpd = NA)
# plot points to prove that this works with some elements
points(1:10, sapply(dat, median), xpd = NA)
关于如何在这种情况下添加小提琴图或箱线图的任何想法?
对于箱线图,我当然可以很容易地自己用rect()和segments()画出来,但是小提琴图更复杂。
【问题讨论】:
标签: r plot violin-plot