简体   繁体   English

在最小值处开始y轴,在0处开始x轴,并使用R中的matplot()使它们相交

[英]starting the y-axis at a minimum value, the x-axes at 0, and making them intersect using matplot() in R

In this question it says my current question was answered by this question ; 这个问题上说我现在的问题被这个问题回答了; however the code suggested doesn't go far enough for me. 但是建议的代码对我来说还远远不够。 These charts need to be suitable for scientific publication, so the effect of yaxs = "i" and xaxs = "i" is not suitable for what I need to produce. 这些图表需要适合科学出版,因此yaxs = "i"xaxs = "i"的效果不适合我需要生成的结果。

The charts displayed in the second link look great, and would be up to the job that I am after, however when I use a similar code for data that does not start at 0: 第二个链接中显示的图表看起来不错,可以很好地完成我所要完成的工作,但是当我对不以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"))

I get the following chart: 我得到以下图表:

在此处输入图片说明

I have simplified the code so I don't use my actual data, and I am using the following objects: 我简化了代码,因此不使用实际数据,而是使用以下对象:

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)

What I would like is to have the axes to cross at (0,6), and horizontal tick points to increment in multiples of 5. 我想让轴在(0,6)处交叉,水平刻度线以5的倍数递增。

Any help with sorting this would be great! 排序方面的任何帮助都将很棒!

Do either of the following get at what you're after? 以下任何一项都可以满足您的要求?

Approach 1: Regular axes (xaxs='r'), with a box? 方法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()

Approach 2: Or tighter axes (xaxs='i'), but with slightly exaggerated x and y limits and a 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM