gpt4 book ai didi

限制R中绘图中水平线的长度

转载 作者:行者123 更新时间:2023-12-02 02:13:01 25 4
gpt4 key购买 nike

我正在尝试使用abline在绘图上绘制水平线

代码如下:

plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

我得到的输出是

Graph I am getting

我在寻找什么 是

Desired polt

如何使abline绘制的线条限制在绘图区域内,如图2所示。

最佳答案

开发有关 xpd 参数如何使用的注释:

来自 par 帮助: xpd 参数是“逻辑值或 NA。如果FALSE,所有绘图都剪切到绘图区域,如果 TRUE,所有绘图都剪切到图形区域,如果 NA,所有绘图都剪切到设备区域"

说明:

par(xpd=T)
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here

同时

par(xpd=F) # this is the default value
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here

最后,

par(xpd=NA,mfrow=c(1,2))
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
abline(h = 0, v = 0, col = "gray60")

给出:

enter image description here

关于限制R中绘图中水平线的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28340094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com