Home > Software engineering >  Low graphic function with arrow
Low graphic function with arrow

Time:10-26

Suppose I am going to draw the following graph.

enter image description here

The empty plot is generated by:

plot(0, 0, type="n", xlim=c(0,2), ylim=c(0,2), bty="n",xlab="", ylab="") 

Now I can use the lty=2 for the dashed line.

My problem is:

Could I control the width of the line to be doubled that of the dotted line, and set the arrow head to have specific length, say, 0.1?

Edit: alright seems I can use the lwd for the width, but I still want to control the arrow head length.

CodePudding user response:

Try this:

plot(0, 0, type="n", xlim=c(0,2), ylim=c(0,2), bty="n",xlab="", ylab="")
x0 <- c(0, 0, 0, 0, 1, 2)
y0 <- c(0, 1, 2, 0, 0, 0)
x1 <- c(2, 2, 2, 0, 1, 2)
y1 <- c(0, 1, 2, 2, 2, 2)
segments(x0, y0, x1, y1, lty=3)
x0 <- c(0, 1, 1, 2)
y0 <- c(2, 2, 1, 1)
x1 <- c(1, 1, 2, 2)
y1 <- c(2, 1, 1, 0)
arrows(x0, y0, x1, y1, lwd=2, length=.1)

Plot

  •  Tags:  
  • r
  • Related