如何使用 boxplot() 将刻度线标签从轴上移开
How to move tick mark labels away from axis using boxplot()
这是一个用于演示的玩具示例:
boxplot(1:90 ~ c({1:90} %% 3),names=c("A","B\nB","C\nC\nC"))
如果你作图,你就会看到我查询的动机。我想将组的刻度标记标签从轴上移开。而且,出于我自己的原因,我不想 "print nothing" 并使用 axes() 函数...相反,我想知道如何通过将参数传递给 boxplot() 调用的子例程来做到这一点。我的理解是这应该是可行的,但迄今为止我已经证明是不成功的。
例如,此处提供的解决方案对于我的目的来说太不优雅了:
R, Change distance between axis tick marks and tick mark labels
¿有人知道怎么做吗?
函数 boxplot()
在检查输入参数的语法后调用 "bxp" 函数。在这里你可以看到它传递给它的参数:
if (plot) {
if (is.null(pars$boxfill) && is.null(args$boxfill))
pars$boxfill <- col
do.call("bxp", c(list(z, notch = notch, width = width,
varwidth = varwidth, log = log, border = border,
pars = pars, outline = outline, horizontal = horizontal,
add = add, at = at), args[namedargs]))
invisible(z)
}
函数 bxp
依次调用函数 "axis" 并且它只查看 "xaxt"、"yaxt"、"xaxp"、
"yaxp"、"las"、"cex.axis"、"col.axis" 绘制轴的参数:
if (axes) {
ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "xaxp",
"yaxp", "las", "cex.axis", "col.axis", "format")]
if (is.null(show.names))
show.names <- n > 1
if (show.names)
do.call("axis", c(list(side = 1 + horizontal, at = at,
labels = z$names), ax.pars))
do.call("Axis", c(list(x = z$stats, side = 2 - horizontal),
ax.pars))
}
从上面可以看出,没有参数可以改变可以传递给boxplot的X标签的偏移量。
默认情况下 ggplot
以您想要的方式显示标签:
df <- data.frame( x= as.factor(c({1:90} %% 3)), y = 1:90 )
ggplot(df,aes(x=x, y=y) ) +
geom_boxplot()+
scale_x_discrete(labels=c("A","B\nB","C\nCC\nCCC"))
这是一个用于演示的玩具示例:
boxplot(1:90 ~ c({1:90} %% 3),names=c("A","B\nB","C\nC\nC"))
如果你作图,你就会看到我查询的动机。我想将组的刻度标记标签从轴上移开。而且,出于我自己的原因,我不想 "print nothing" 并使用 axes() 函数...相反,我想知道如何通过将参数传递给 boxplot() 调用的子例程来做到这一点。我的理解是这应该是可行的,但迄今为止我已经证明是不成功的。
例如,此处提供的解决方案对于我的目的来说太不优雅了:
R, Change distance between axis tick marks and tick mark labels
¿有人知道怎么做吗?
函数 boxplot()
在检查输入参数的语法后调用 "bxp" 函数。在这里你可以看到它传递给它的参数:
if (plot) {
if (is.null(pars$boxfill) && is.null(args$boxfill))
pars$boxfill <- col
do.call("bxp", c(list(z, notch = notch, width = width,
varwidth = varwidth, log = log, border = border,
pars = pars, outline = outline, horizontal = horizontal,
add = add, at = at), args[namedargs]))
invisible(z)
}
函数 bxp
依次调用函数 "axis" 并且它只查看 "xaxt"、"yaxt"、"xaxp"、
"yaxp"、"las"、"cex.axis"、"col.axis" 绘制轴的参数:
if (axes) {
ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "xaxp",
"yaxp", "las", "cex.axis", "col.axis", "format")]
if (is.null(show.names))
show.names <- n > 1
if (show.names)
do.call("axis", c(list(side = 1 + horizontal, at = at,
labels = z$names), ax.pars))
do.call("Axis", c(list(x = z$stats, side = 2 - horizontal),
ax.pars))
}
从上面可以看出,没有参数可以改变可以传递给boxplot的X标签的偏移量。
默认情况下 ggplot
以您想要的方式显示标签:
df <- data.frame( x= as.factor(c({1:90} %% 3)), y = 1:90 )
ggplot(df,aes(x=x, y=y) ) +
geom_boxplot()+
scale_x_discrete(labels=c("A","B\nB","C\nCC\nCCC"))