4

我正在根据plot()R 中使用的因子绘制连续变量(参见下面的示例)。我不想要轴上的标签。如果没有as.factor公式中的调用会ann = F抑制标签的打印,但它在公式中不起作用as.factor

为什么是这样?

谢谢你。

# example for SO
# example data 
x <- sample(1:100, 10)
y <- c(rep(1, 5), rep(2, 5))

# ann = F doesn't work here
plot(x ~ as.factor(y), ann = F)

# ann = F does work here
plot(x ~ y, ann = F)
4

2 回答 2

5

这似乎是plot.formula由于如果您单独指定它可以x工作y

plot(as.factor(y), x, ann=FALSE)

更新:

确认它在graphics:::plot.formula. 显式调用的行plot设置ylaband xlab(funname"plot"and dots= list(ann=FALSE)):

do.call(funname, c(list(mf[[i]], y, ylab = yl, xlab = xl), dots))
于 2011-06-01T19:21:48.707 回答
2

调度系统将不工作的发送到 plot.factor,然后发送到 boxplot,它没有 ann= 参数,而“工作”的发送到 plot.data.frame,它转到 plot。最终默认,这确实尊重 ann= 参数。压制命名。采用:

plot(x ~ as.factor(y), names = rep("", 2))

于 2011-06-01T19:24:05.440 回答