我一直在练习图表以及如何使用以下代码在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))
现在我想跟踪线条的确切连接方式以形成此模式,因此使用了以下代码。
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))
线条不应该连接点吗?我使用此代码
得到线条连接点的输出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")
如果我稍后添加积分,他们也不会工作。
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)
为什么输出会有这样的差异?
答案 0 :(得分:2)
在绘制点plot.window
之后和绘制线plot(...)
导致不匹配之前,您设置了lines(...)
限制。请尝试以下方法:
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))