【问题标题】:cex.axis only affects y-axis, not x-axiscex.axis 只影响 y 轴,不影响 x 轴
【发布时间】:2013-12-23 14:20:37
【问题描述】:

我在子集 A1 中绘制了因子变量“答案”的图。我想减小两个轴上的文本大小,以适应 x 轴上的两个极值。但是,使用 cex.axis 时,仅影响 y-label 上的字体大小,而不影响 x 轴上的字体大小。为什么会这样,我该如何改变呢?

我使用的函数是:

plot(A1$answer, main = "Would you recommend edX to a friend of you?", xlab = "Answer", ylab = "#students", col='lightblue', cex.axis=0.75, font=3, family='mono'); box(col='lightblue');

这是输出:

【问题讨论】:

  • A1$answer 是什么类?你有没有机会使用barplot 而不是plot?在这种情况下尝试cex.names = 0.75
  • A1$answer 是序数因子水平。 // 我已经尝试过的条形图 - 给出错误'高度'必须是向量或矩阵'

标签: r plot


【解决方案1】:

当您在factor 变量x 上使用plot 时,它默认调用barplot(或者更准确地说是barplot(table(x)),即您可以查看?barplot 以获取提示。在这种情况下,正如我在 cmets 中提到的,x-axis 被视为标签,而不是数字轴,因此您需要像这样使用cex.names

tab <- as.ordered(sample(1:10, 100, replace = TRUE))
plot(tab, cex.axis = 0.75, cex.names = 0.75)

另外,如上所述,如果你想直接使用barplot,你需要先做一个表

barplot(table(tab), cex.axis = 0.75, cex.names = 0.2)

【讨论】:

    【解决方案2】:

    我刚刚偶然发现了 lattice 中的 barchart 函数,它的输出要好得多:

    【讨论】:

    • 但我现在看到它没有回答问题。只是提供了一个替代方案。
    猜你喜欢
    • 2019-08-14
    • 2015-03-18
    • 2018-12-24
    • 1970-01-01
    • 2012-02-08
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    相关资源
    最近更新 更多