【问题标题】:starting the y-axis at a minimum value, the x-axes at 0, and making them intersect using matplot() in R从最小值开始 y 轴,从 0 开始 x 轴,并使用 R 中的 matplot() 使它们相交
【发布时间】:2019-02-07 16:58:49
【问题描述】:

this question 中表示我当前的问题已由this question 回答;但是建议的代码对我来说还不够。这些图表需要适合科学发表,所以yaxs = "i"xaxs = "i"的效果不适合我需要制作的。

第二个链接中显示的图表看起来很棒,可以胜任我的工作,但是当我对不从 0 开始的数据使用类似代码时:

matplot(times, cbind(a, b, c),
    pch = 1,
    col = c("red", "blue", "green"),
    lty = c(1, 1, 1),
    xlab = "Time (s)",
    ylab = "Flourescense Yield (RFU)",
    main = "test",
    xlim = c(0 , max(times)),
    ylim = c(min(a, b, c) - 0.1* min(a, b, c), max(a, b, c) + 0.1* max(a, b, c)),
    axes = FALSE)
axis(1, pos = 0, at = 0: round(times))
axis(2, pos = 0, at = round(min(a, b, c)): round(max(a, b, c)))

legend("topright", y =NULL, c("Biocomposite 1", "Biocomposite 2", "Biocomposite 3"),
       text.col = c("red", "blue", "green"))

我得到以下图表:

我已经简化了代码,所以我不使用我的实际数据,我正在使用以下对象:

a <- sample(1:100, 10, replace = TRUE)

b <- sample(1:100, 10, replace = TRUE)

c <- sample(1:100, 10, replace = TRUE)

times <- c(0:9)

我想要的是让轴在 (0,6) 处交叉,水平刻度点以 5 的倍数递增。

任何关于排序的帮助都会很棒!

【问题讨论】:

  • 有什么理由在这里使用 matplot() 而不是 base R?使用 base r,par() 设置轴截距,plot() 用于第一个系列,points() 用于第二系列,points() 用于第三系列,axes() 两次用于自定义轴,legend(),然后将其全部包裹png() 并且您可以有一个准备好发布的图...
  • 嗨,JoelnNC。感谢您的建议,我只是选择了 matplot,因为它似乎很容易完成所需的操作。查看 par() 的帮助页面时,我只能找到 yaxs 和 xaxs 的命令,这些命令与我的图表有问题。干杯

标签: r axes intercept


【解决方案1】:

以下任何一项都能满足您的需求吗?

方法 1:规则轴 (xaxs='r'),带框?

dev.new()
par(xaxs="r", yaxs="r")
plot(times, a, pch=1, col="red", axes=F, xlab=NA, ylab=NA)
axis(side=1, at=times)
mtext("Times (s)", side=1, line=2.5)
axis(side=2, at=seq(0,100,10))
mtext("Flourescense Yield", side=2, line=2.5)
points(times, b, col="blue")
box()

方法 2:或更紧的轴 (xaxs='i'),但稍微夸大了 x 和 y 限制以及一个框?

dev.new()
par(xaxs="i", yaxs="i")
plot(times, a, pch=1, col="red", axes=F, xlab=NA, ylab=NA,
     xlim=c(-.5,9.5), ylim=c(-2,102))
axis(side=1, at=times)
mtext("Times (s)", side=1, line=2.5)
axis(side=2, at=seq(0,100,10))
mtext("Flourescense Yield", side=2, line=2.5)
points(times, b, col="blue")
box()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    • 2020-07-19
    • 2018-01-29
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多