📜  在 R 编程中绘制图中点之间的箭头 – arrows()函数

📅  最后修改于: 2022-05-13 01:55:33.834000             🧑  作者: Mango

在 R 编程中绘制图中点之间的箭头 – arrows()函数

R 语言中的arrows()函数用于在指定图形上的点之间创建箭头。

示例 1:

# Specifying points
x0 <- 1
y0 <- 1
x1 <- 5
y1 <- 5
x <- c(x0, x1)
y <- c(y0, y1)
  
# Output to be present as PNG file
png(file = "arrows1GFG.png")
  
# Create plot graph
plot(x, y, main = "Arrows Function")
  
# Create arrow between the points
arrows(x0, y0, x1, y1)
  
# Saving the file
dev.off()

输出:

示例 2:

# Specifying points
x <- runif(10, 0, 1)
y <- runif(10, 1, 5)
  
# Output to be present as PNG file
png(file = "arrows2GFG.png")
  
# Create plot graph
plot(x, y, main = "Arrows Function")
  
# Create arrow between the points
s <- seq(length(x) - 1)
arrows(x[s], y[s], x[s + 1], y[s + 1])
  
# Saving the file
dev.off()

输出: