将 R 绘图 x 轴设置为在 y=0 处显示

发布于 2024-09-13 16:16:05 字数 121 浏览 0 评论 0原文

通常,当我绘制一些 R 线图并设置 ylim=c(0,some_value) 时,x 轴和 y=0 之间有很小的空间。

我希望 y 轴精确显示在 y=0 处,因此点 (x,0) 将绘制在 y 轴上(而不是上面)。

Usually when I plot some R line plot and set ylim=c(0,some_value), there is small space between the x axis and y=0.

I would like the y axis to show exactly at y=0 so points (x,0) will be plotted on the y axis (and not above).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轮廓§ 2024-09-20 16:16:05

您可能需要样式为“i”的图形参数 xaxsyaxs

plot(1:10, rnorm(10), ylim=c(0,10), yaxs="i")

请参阅 ?par

xaxs:轴间隔的样式
用于 x 轴的计算。
可能的值为“r”、“i”、“e”、
“s”、“d”。款式一般有
由数据范围控制或
xlim,如果给出的话。样式“r”(常规)
首先将数据范围扩展4
每一端的百分比,然后找到一个
带有漂亮标签的轴,适合
扩展范围内。风格“我”
(内部)只是找到一个轴
适合的漂亮标签
原始数据范围。样式“s”
(标准)找到一个漂亮的轴
原始数据所在的标签
范围适合。样式“e”(扩展)是
类似于“s”样式,不同之处在于它也是
确保有空间
在边界内绘制符号
盒子。样式“d”(直接)指定
当前轴应该用于
后续情节。 (仅“r”和“i”
目前已实现样式)

yaxs:用于 y 轴的轴间隔计算样式。
请参阅上面的 xaxs

You probably want the graphical parameters xaxs and yaxs with style "i":

plot(1:10, rnorm(10), ylim=c(0,10), yaxs="i")

See ?par:

xaxs: The style of axis interval
calculation to be used for the x-axis.
Possible values are "r", "i", "e",
"s", "d". The styles are generally
controlled by the range of data or
xlim, if given. Style "r" (regular)
first extends the data range by 4
percent at each end and then finds an
axis with pretty labels that fits
within the extended range. Style "i"
(internal) just finds an axis with
pretty labels that fits within the
original data range. Style "s"
(standard) finds an axis with pretty
labels within which the original data
range fits. Style "e" (extended) is
like style "s", except that it is also
ensures that there is room for
plotting symbols within the bounding
box. Style "d" (direct) specifies that
the current axis should be used on
subsequent plots. (Only "r" and "i"
styles are currently implemented)

yaxs: The style of axis interval calculation to be used for the y-axis.
See xaxs above.

陌路黄昏 2024-09-20 16:16:05

另一种选择是使用axes=F禁用绘图中的轴绘制,然后使用axis命令单独放置轴,并使用pos选项控制轴间距。

plot(1:10, runif(10), ylim=c(0,1), xlim=c(0,10),axes=F)
     axis(1, pos=0)
     axis(2, pos=0)   

Another option is to disable the axis plotting in plot using axes=F and then put the axes in separately using the axis command, with the pos option controlling the axis spacing.

plot(1:10, runif(10), ylim=c(0,1), xlim=c(0,10),axes=F)
     axis(1, pos=0)
     axis(2, pos=0)   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文