检查功能后
shapes::rotatexy
,我自己找到了解决方案:我需要解决纵横比问题。最后,我想出了以下对我来说很有用的函数:
my_arrow <- function(x,y, rotate=0, col=par("fg"), border=par("fg"), cex=1) {
scale_base <- strwidth("O")/2.4
xbase <- c(1.2,0.2,0.2,-1.2, -1.2, 0.2, 0.2) * scale_base
ybase <- c(0,1,0.5,0.5,-0.5,-0.5,-1) * scale_base
rotM <- matrix(c(cos(rotate*pi/180), sin(rotate*pi/180), -sin(rotate*pi/180), cos(rotate*pi/180)), nrow=2)
transf <- function(x1,y1) cex * rotM %*% c(x1,y1) + c(x,y)
ans <- t(mapply(transf, xbase, ybase))
# this is deliberately taken from shapes::rotatexy
user <- par("usr")
pin <- par("pin")
sy <- user[4] - user[3]
sx <- user[2] - user[1]
ans[,2] <- y + (ans[,2]-y) * sy/sx * pin[1]/pin[2]
polygon(x=ans[,1], y=ans[,2], col=col, border=border)
}
所以,当我打电话时:
plot(1:2, type="p", col="white", xlim=c(-5,5), ylim=c(-10,10))
my_arrow(0,0, rotate=45, cex=5)
我得到了我想要的: