[英]How to overlay two lines using the -plot- function in R
I am using R version 3.6.0.我正在使用 R 版本 3.6.0。 I am trying to overlay 3 lines on a single plot.
我试图在单个 plot 上覆盖 3 行。 I have done this successfully in the past using identical code and for some reason it doesn't seem to be working.
我过去使用相同的代码成功地完成了这项工作,但由于某种原因它似乎不起作用。 I have the following RWE:
我有以下 RWE:
y.l <- function(x){0.024 - 0.00004*x + 0.00001*(10-16.8764)}
y.a <- function(x){0.024 - 0.00004*x}
y.h <- function(x){0.024 - 0.00004*x + 0.00001*(20-16.8764)}
png("yplot.png")
yplot <- plot(y.l(1:800),
type="l", lty=2,
xlab="x", ylab="y", main="Getting better :/",
ylim=c(-0.025,0.025))
lines(1:800, lty=1, y.a(1:800))
lines(1:800, lty=3, y.h(1:800))
dev.off()
which produces the following plot:产生以下 plot:
For some reason it is ignoring the extra -lines()- code.由于某种原因,它忽略了额外的 -lines()- 代码。 Is there some obvious mistake I am overlooking after staring at a computer all day?
整天盯着电脑看,我是否忽略了一些明显的错误? I have done this exact same thing before and I cannot for the life of me figure it out.
我以前做过同样的事情,但我终其一生都无法弄清楚。 And yes I have expanded the y-axis to see if they were hiding above or below and they aren't.
是的,我已经扩展了 y 轴以查看它们是隐藏在上方还是下方,而实际上不是。
Your 3 lines are plotted, it is because of your function that you can't see them.绘制了 3 条线,这是因为您的 function 看不到它们。 Here the output of your three function:
这里是你的三个 function 的 output:
> head(y.a(1:800))
[1] 0.02396 0.02392 0.02388 0.02384 0.02380 0.02376
> head(y.h(1:800))
[1] 0.02399124 0.02395124 0.02391124 0.02387124 0.02383124 0.02379124
> head(y.l(1:800))
[1] 0.02389124 0.02385124 0.02381124 0.02377124 0.02373124 0.02369124
You can see that your three function give almost the same results, it because of your 0.00001*(10-16.8764)
that's is basically to small to modify your output.您可以看到您的三个 function 给出几乎相同的结果,这是因为您的
0.00001*(10-16.8764)
对修改您的 output 来说基本上太小了。
If you zoom enough on the plot:如果你在 plot 上放大到足够大:
yplot <- plot(y.l(1:800),
type="l", lty=2,
xlab="x", ylab="y", main="Getting better :/",
ylim=c(.023,0.024),
xlim=c(0,30))
lines(1:800, lty=1, y.a(1:800))
lines(1:800, lty=3, y.h(1:800))
You can see the three lines:你可以看到三行:
I think you need to change the last parameter of your function if you want to see a dramatic difference between your lines.如果你想看到你的线条之间的巨大差异,我认为你需要更改 function 的最后一个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.