将向量绘制为r中的线

发布于 2025-02-09 21:15:31 字数 359 浏览 1 评论 0原文

我有这样的向量:

vec<-c(NA,1,1,NA,NA,NA,1,NA)

我该如何绘制这样的绘制:

我已经准备好了一个情节,我只想在当前的情节中添加类似的行。因此,我尝试使用行:

line(vec)

但是我有一个错误。我该如何实现我想做的事情?

I have a vector like this:

vec<-c(NA,1,1,NA,NA,NA,1,NA)

How can I plot it like this:
enter image description here

I already have a plot ready, I just want to add a line like above to my current plot. So I tried using line:

line(vec)

But I am having an error. How can I achieve what I want to do?

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

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

发布评论

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

评论(1

梦明 2025-02-16 21:15:31

这样的东西?
注意seq_along作为x轴坐标的使用。类型“ n”的图,这意味着没有图,只需设置适当宽度和高度的绘图区域即可。

vec<-c(NA,1,1,NA,NA,NA,1,NA)

plot(seq_along(vec), vec, type = "n", xlab = "", ylab = "")
lines(seq_along(vec), vec, xlab = "", ylab = "")
points(seq_along(vec), vec, pch = 19, xlab = "", ylab = "")

“”

在2022-06-23上由 reprex软件包(v2.0.1)


数据集cars可能不是最好的示例,因为轴范围不匹配vec的s,但这是一个图。

vec <- c(NA,1,1,NA,NA,NA,1,NA)

plot(cars, main = "Stopping Distance versus Speed", xlim = c(0, 25))
lines(seq_along(vec), vec, xlab = "", ylab = "")
points(seq_along(vec), vec, pch = 19, xlab = "", ylab = "")

“”

在2022-06-23上由 reprex软件包(v2.0.1)

Something like this?
Note the use of seq_along as x axis coordinates. And of a plot of type "n", meaning no plot, just set the plot area with appropriate width and height.

vec<-c(NA,1,1,NA,NA,NA,1,NA)

plot(seq_along(vec), vec, type = "n", xlab = "", ylab = "")
lines(seq_along(vec), vec, xlab = "", ylab = "")
points(seq_along(vec), vec, pch = 19, xlab = "", ylab = "")

Created on 2022-06-23 by the reprex package (v2.0.1)


The data set cars is probably not the best example since the axis ranges do not match vec's, but here is a plot.

vec <- c(NA,1,1,NA,NA,NA,1,NA)

plot(cars, main = "Stopping Distance versus Speed", xlim = c(0, 25))
lines(seq_along(vec), vec, xlab = "", ylab = "")
points(seq_along(vec), vec, pch = 19, xlab = "", ylab = "")

Created on 2022-06-23 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文