如何在R中给定特定位置绘制三角形?

Fen*_*ian -4 plot r

鉴于三角形的点位置是:

c(0,0)
c(1,0)
c(0,1)
Run Code Online (Sandbox Code Playgroud)

如何在R中获得绿色三角形?

cle*_*ens 5

对于向量:

x <- c(0, 1, 0)
y <- c(0, 0, 1)
Run Code Online (Sandbox Code Playgroud)

创建一个情节:

plot(x, y)
Run Code Online (Sandbox Code Playgroud)

您可以使用polygon()添加三角形:

polygon(x, y)
Run Code Online (Sandbox Code Playgroud)

结果是:

在此处输入图片说明

要创建绿色边框,请使用:

polygon(x, y, border = 'green')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

要创建绿色区域,请使用:

polygon(x, y, col = 'green')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明