简体   繁体   English

lines()函数未连接图形中的实际点

[英]lines() function is not connecting the actual points in the graph

I have been practicing the graphs and how to plot in R with the following code 我一直在练习图形以及如何使用以下代码在R中进行绘制

theta = 1:100
x = sin(theta)
y = cos(theta)
op = par(bg = 'white', mar = rep(1, 4))
plot.new()
plot(x,y)
plot.window(xlim = c(-1, 1), ylim = c(-1, 1))
lines(x, y, col = hsv(0.95, 1, 1))

to get the following output 得到以下输出 在此处输入图片说明

Now I wanted to trace just how exactly the lines connect to form this pattern and so used the following code. 现在,我想跟踪连接线的精确度以形成此模式,因此使用以下代码。

theta = 1:3
x = sin(theta)
y = cos(theta)
op = par(bg = 'white', mar = rep(1, 4))
plot(x,y, xlab = "Sin", ylab = "Cos", type = "p")
plot.window(xlim = c(-1, 1), ylim = c(-1, 1))
lines(x, y, col = hsv(0.95, 1, 1))

And I get the following output 我得到以下输出 在此处输入图片说明

Shouldn't the lines connect the dots? 线条不应该连接点吗? I get the output where the lines connect the dots using this code 我得到的输出是使用此代码的线连接点的地方

theta = 1:3
x = sin(theta)
y = cos(theta)
op = par(bg = 'white', mar = rep(1, 4))
plot(x,y, xlab = "Sin", ylab = "Cos", type = "l")

在此处输入图片说明

And if I add the points later, they don't work as well. 而且,如果以后再添加这些点,它们将无法正常工作。

theta = 1:3
x = sin(theta)
y = cos(theta)
op = par(bg = 'white', mar = rep(1, 4))
plot(x,y, xlab = "Sin", ylab = "Cos", type = "l")
plot.window(xlim = c(-1, 1), ylim = c(-1, 1))
points(x, y)

Here is the output. 这是输出。 在此处输入图片说明

Why is there such difference in output? 为什么输出会有这种差异?

You are setting plot.window limits after you have plotted your points plot(...) and before plotting your lines lines(...) causing the mismatch. 要设置plot.window限制你绘制你的观点后, plot(...)并绘制你的前行lines(...)引起的不匹配。 Try the following: 请尝试以下操作:

theta = 1:3
x = sin(theta)
y = cos(theta)
op = par(bg = 'white', mar = rep(1, 4))
plot.window(xlim = c(-1, 1), ylim = c(-1, 1))
plot(x,y, xlab = "Sin", ylab = "Cos", type = "p")
lines(x, y, col = hsv(0.95, 1, 1))

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

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