如何绘制线段的轮廓

时间:2013-08-14 14:15:48

标签: r graphics plot segments

我正在使用R函数segments,并且想知道我如何能够“围绕”段(轮廓),例如黑色。

plot(0)
segments(.9,.1,.8,.3, lwd=10, lend='square', col='pink')

在这里,我会在粉红色部分周围看到一个黑色矩形 enter image description here

2 个答案:

答案 0 :(得分:1)

您可以绘制两次,首先是黑色,大(lwd=12),然后是粉红色,小(lwd=10)。

plot(0)
segments(.9,.1,.8,.3, lwd=12, lend='square', col='black')
segments(.9,.1,.8,.3, lwd=10, lend='square', col='pink')

答案 1 :(得分:0)

这非常混乱,但无论如何我把它扔在了一起。

draw.rect <- function(x1=0.9,y1=0.1,x2=0.8,y2=0.3,width=0.05){
  ang <- atan((y2-y1)/(x2-x1))
  xshift <- width*sin(ang)
  yshift <- width*cos(ang)
  polygon(x=c(x1,x2,x2-xshift,x1-xshift),y=c(y1,y2,y2+yshift,y1+yshift),col="pink")
}

它允许您使用相同的坐标。您可以使用width参数调整矩形的大小。我认为@VincentZoonekynd有两个绘制片段的好主意。这个粗略的功能不会将矩形置于所提供的坐标上,尽管您可以非常轻松地对其进行调整。

相关问题