【问题标题】:Coordinates of A Boxplot Legend with Categorical X-Axis具有分类 X 轴的箱线图图例的坐标
【发布时间】:2021-03-26 14:59:55
【问题描述】:

我有一个带有 2 个条的箱线图:

boxplot(mtcars$mpg,mtcars$qsec)

我想使用坐标在右下角添加一个图例。 我如何知道下面图例函数 (x) 的 x,y 坐标的 x 值是多少?

legend(x,15,legend=c("mpg","qsec"))

【问题讨论】:

  • 我认为每个框都以一个整数值为中心,整数从 1 开始,最左边的框并向右移动连续增加。

标签: r data-visualization boxplot


【解决方案1】:

为什么要使用坐标?如果你放弃这个条件,这很容易:改用名称“bottomright”,即

legend("bottomright", legend = c("mpg","qsec"))

如果您不希望它精确地位于角落,您可以使用 inset 参数,例如

boxplot(mtcars$mpg,mtcars$qsec)
legend("bottomright", legend = c("mpg","qsec"), inset = c(0.01, 0.02))

reprex package (v1.0.0) 于 2021-03-26 创建

【讨论】:

    猜你喜欢
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 2016-09-03
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多