英文:
Why are they getting joined? The values are different
问题
X <- c('1.07', '2.14', '3.22', '4.29')
Y <- c(0.298, 0.272, 0.271, 0.270)
Y1 <- c(0.274, 0.269, 0.255, 0.249)
par(mar = c(0.1, 0.1, 0.1, 0.1) + 2)
plot(X, Y, xlab= "VG高度(毫米)", ylab= "阻力系数(Cd)",
main = "VG高度 vs. 阻力系数", type= "o", pch = 20,
lwd = 2, col = "red")
par(new = TRUE)
plot(X, Y1, xlab= "", ylab= "", main = "", axes = FALSE, type= "o",
pch = 20, lwd = 2, col = "blue")
我尝试生成两个Y轴。但是,两条线都连接在一起,尽管它们具有不同的值。
英文:
X <- c('1.07', '2.14', '3.22', '4.29')
Y <- c(0.298, 0.272, 0.271, 0.270)
Y1 <- c(0.274, 0.269, 0.255, 0.249)
par(mar = c(0.1, 0.1, 0.1, 0.1) + 2)
plot(X, Y, xlab= "Height of the VG (in mm)", ylab= "Drag Co-efficient (Cd)",
main = "Height of the VG vs. Drag Co-efficient", type= "o", pch = 20,
lwd = 2, col = "red")
par(new = TRUE)
plot(X, Y1, xlab= "", ylab= "", main = "", axes = FALSE, type= "o",
pch = 20, lwd = 2, col = "blue")
I'm trying to generate two y axes. But, both the lines are getting joined, even though with different value.
答案1
得分: 1
问题出在y轴限制上,图表未使用相同的数值。首先创建一个名为 ylim
的向量,其中包含 Y
和 Y1
的常用值,然后在图表中使用它。
X <- c('1.07', '2.14', '3.22', '4.29')
Y <- c(0.298, 0.272, 0.271, 0.270)
Y1 <- c(0.274, 0.269, 0.255, 0.249)
# 保存默认值
old_par <- par(mar = c(0.1, 0.1, 0.1, 0.1) + 2)
# 定义y轴限制
ylim <- range(c(Y, Y1))
plot(
X, Y,
# 设置y轴限制
ylim = ylim,
xlab = "VG的高度(毫米)",
ylab = "阻力系数(Cd)",
main = "VG高度与阻力系数",
type = "o",
pch = 20,
lwd = 2,
col = "red"
)
par(new = TRUE)
plot(
X, Y1,
# 设置y轴限制为
# 与上述相同的值
ylim = ylim,
xlab = "",
ylab = "",
main = "",
axes = FALSE,
type = "o",
pch = 20,
lwd = 2,
col = "blue"
)
英文:
The problem is in the y axis limits, the plots are not using the same values. Below I first create a vector ylim
with values common to Y
and Y1
, then use it in the plots.
X <- c('1.07', '2.14', '3.22', '4.29')
Y <- c(0.298,0.272,0.271,0.270)
Y1 <- c(0.274,0.269,0.255,0.249)
# save the default values
old_par <- par(mar = c(0.1, 0.1, 0.1, 0.1) + 2)
# define the y axis limits
ylim <- range(c(Y, Y1))
plot(
X, Y,
# set the y axis limits
ylim = ylim,
xlab = "Height of the VG (in mm)",
ylab= "Drag Co-efficient (Cd)",
main = "Height of the VG vs. Drag Co-efficient",
type= "o",
pch = 20,
lwd = 2,
col = "red"
)
par(new = TRUE)
plot(
X, Y1,
# set the y axis limits to the
# same value as above
ylim = ylim,
xlab= "",
ylab= "",
main = "",
axes = FALSE,
type = "o", pch = 20,
lwd = 2,
col = "blue"
)
<!-- -->
# restore default values
par(old_par)
<sup>Created on 2023-06-12 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论