R:向布局的网格添加箭头

R:向布局的网格添加箭头,r,plot,R,Plot,我使用布局来绘制多个图形,我想在这些图形之间添加箭头。我试过grid.curve和grid.lines(),但到目前为止运气不好。 下面是我想做的一个例子: mat <- cbind(matrix(c(1:3,0,4:5,0,6,7),3,3,byrow=T), 8:10) m<-layout(mat) layout.show(m) cars <- c(1, 3, 6, 4, 9) trucks <- c(2, 5, 4, 5, 12) plot(cars, type="

我使用布局来绘制多个图形,我想在这些图形之间添加箭头。我试过grid.curve和grid.lines(),但到目前为止运气不好。 下面是我想做的一个例子:

mat <- cbind(matrix(c(1:3,0,4:5,0,6,7),3,3,byrow=T), 8:10)
m<-layout(mat)
layout.show(m)
cars <- c(1, 3, 6, 4, 9)
trucks <- c(2, 5, 4, 5, 12)
plot(cars, type="o", col="blue")
plot(trucks, type="o", pch=22, lty=2, col="red")
plot(cars, type="o", col="blue", ylim=c(0,12))
lines(trucks, type="o", pch=22, lty=2, col="red")
barplot(cars)
barplot(trucks)
hist(cars)
pie(cars)
library(gplots)
textplot(mat)

mat如果你不需要什么特别的东西,你可以试试
箭头。
两个简单的黑色直箭头:

x <- -2
y <- -0.1
arrows(x0=x, y0=y, x1=x, y1=y-0.2, xpd=NA, length=0.05)

x <- -1.55
y <- -1.3
arrows(x0=x, y0=y, x1=x+0.5, y1=y-0.6, xpd=NA, length=0.05)

x我试图用一种基本的方式来解决它

:
textplot(mat)

par.old <- par(no.readonly=T)            # preserve old par
par(new=T, mfrow=c(1,1), mar=c(0,0,0,0))
plot(0,0, type="n", axes=F, ann=F)       # make empty plot

a <- locator(4)                          # locator() returns xy coordinates at a click point
# click on the plot four times (first arrow's start point, end point, second arrow's …)

arrows(a$x[1], a$y[1], a$x[1], a$y[2], length=0.1)  # use same x ( a$x[2] is unnecessary ).
arrows(a$x[3], a$y[3], a$x[4], a$y[4], length=0.1)

par(par.old)
:
文本打印(mat)

Pr.Hythor非常感谢,但是由于我的布局比这个大一点,所以计算出坐标可能是费时费力的。我尝试了一些数字,但还没有箭头。我想你可以像这样算出坐标:
f谢谢,但这对我不起作用,因为我需要生成多个这样的图,所以每次使用locator()是没有意义的,而且我正在使用layout()。