我不确定我完全理解你想要什么,但可能是这样:为每个箱线图添加一行,该行覆盖与箱线图相同的x轴范围。
箱子的宽度由pars$boxwex
控制,默认设置为0.8。这可以从boxplot.default
的参数列表中看到:
formals(boxplot.default)$pars
## list(boxwex = 0.8, staplewex = 0.5, outwex = 0.5)
# create sample data and box plot
set.seed(123)
datatest <- data.frame(a = rnorm(100, mean = 10, sd = 4),
b = rnorm(100, mean = 15, sd = 6),
c = rnorm(100, mean = 8, sd = 5))
boxplot(datatest)
# create data for segments
n <- ncol(datatest)
# width of each boxplot is 0.8
x0s <- 1:n - 0.4
x1s <- 1:n + 0.4
# these are the y-coordinates for the horizontal lines
# that you need to set to the desired values.
y0s <- c(11.3, 16.5, 10.7)
# add segments
segments(x0 = x0s, x1 = x1s, y0 = y0s, col = "red")
abline
三次将无论绘图中存在多少个箱线图,都会向其添加三条线。如果您需要在特定x
范围内的水平线,则可以查看segments
函数。 - narendra-choudhary