【问题标题】:Change Axis Label - R scatterplot更改轴标签 - R 散点图
【发布时间】:2014-05-29 20:55:55
【问题描述】:

我正在使用 CAR 库散点图函数尝试执行类似于 R: Replace X-axis with own values 的操作。但是结果格式错误。有谁知道使用散点图时如何替换 x 轴值?我的代码如下

library(car)
dat = data.frame(x=1:10, y=1:10)
scatterplot(y~x, data=dat, xlab="X axis", ylab="Y Axis", xaxt="n")
axis(1, at=seq(1,10,2), labels=letters[1:5])

使用生成的图像

【问题讨论】:

  • xlim=c(lower:upper) ?
  • “结果格式错误”究竟是什么意思?
  • @hd - 将其添加到 axes(..) 似乎并没有改变任何东西。您可以使用 pos=1.2 摆脱垂直空间,但我没有找到任何可以更改为水平对齐或间距的东西
  • @BondedDust - 我认为从图片上看会很明显,但是沿 x 轴的字母标签在比例和间距上都与刻度线不对齐。如果您查看链接,您可以与我认为格式正确的图表进行对比。
  • 我以为你指的是字母是如何产生的。您实际上对标签和刻度线的注册感到困扰。

标签: r r-car


【解决方案1】:

阅读car:::scatterplot 帮助页面,这似乎是我生命中的呼唤,....

reset.par   if TRUE then plotting parameters are reset to their previous values when scatterplot 
            exits; if FALSE then the mar and mfcol parameters are altered for the current 
            plotting device. Set to FALSE if you want to add graphical elements (such as lines) 
            to the plot.

将其设置为 FALSE 并重试。

png(); scatterplot(y~x, data=dat, xlab="X axis", ylab="Y Axis", xaxt="n", reset.par=FALSE)
 axis(1, at=seq(1,10,2), labels=letters\[1:5\])
dev.off()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    相关资源
    最近更新 更多