在 R 编程中绘制图中点之间的箭头 – arrows()函数
R 语言中的arrows()
函数用于在指定图形上的点之间创建箭头。
Syntax: arrows(x0, y0, x1, y1, length)
Parameters:
x0: represents x-coordinate of point from which to draw the arrow
y0: represents y-coordinate of point from which to draw the arrow
x1: represents x-coordinate of point to which the arrow is drawn
y1: represents y-coordinate of point to which the arrow is drawn
length: represents length of the edge of the arrow head (in inches)
示例 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()
输出: