R语言 绘制图形中各点之间的箭头 – arrows()函数

R语言 绘制图形中各点之间的箭头 – arrows()函数

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

语法: arrows(x0, y0, x1, y1, length)

参数:

x0: 代表绘制箭头的点的x坐标

y0: 代表绘制箭头的点的y坐标

x1: 代表绘制箭头的点的x坐标

y1: 代表绘制箭头的点的y坐标

length: 代表箭头头的边缘长度(英寸)。

例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()

输出:

在R语言编程中绘制图形中各点之间的箭头 - arrows函数

例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()

输出:

在R语言编程中绘制图形中各点之间的箭头 - arrows函数

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程