简体   繁体   English

如何在R中的绘图中的箭头上添加文本

[英]How add a text over an arrow in a plot in R

I plotted two points in a graph using R and connected the points with an arrow. 我使用R在图形中绘制了两个点,并用箭头将这些点连接起来。 How can I add a text over the arrow.(Fixed Text) My codes are as following: 如何在箭头上添加文本。(固定文本)我的代码如下:

x<-y<-1
new.x<-2
new.y<-2  
Text<-"Direction"
plot(x, y, xaxt='n',yaxt='n',cex=10,pch=19,xlim=c(0,4), ylim=c(0,3))
points(new.x,new.y,cex=10,pch=19)
arrows(x, y, new.x, new.y, col = "orange",lwd=4,lty=4)

on the arrow I want to add a Text object ("Direction") on the arrow. 我想在箭头上添加一个Text对象(“方向”)。

The image is as following: 图像如下:

包含上方文字的箭头

Have you looked at using text ? 您看过使用文字吗?

eg, 例如,

x<-y<-1
new.x<-2
new.y<-2  
Text<-"Direction"
plot(x, y, xaxt='n',yaxt='n',cex=10,pch=19,xlim=c(0,4), ylim=c(0,3))
  points(new.x,new.y,cex=10,pch=19)
  arrows(x, y, new.x, new.y, col = "orange",lwd=4,lty=4)
  text(x=1.4, y=1.6, label=Text, srt=35)

图片输出

Depending on what you're doing, can probably programmatically sort out the coordinates for the text and the appropriate angle. 根据您的操作,可能可以以编程方式整理出文本的坐标和适当的角度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM