【问题标题】:using a pos vector with text in R在 R 中使用带有文本的 pos 向量
【发布时间】:2014-12-08 23:02:34
【问题描述】:

我正在尝试使用text 在我的情节中添加一些文字。我想在向量中使用pos 参数,这样我就可以指定将哪些词放在(例如)指定坐标上方。但是我不知道要在向量中放入什么以便将某些文本元素保持在指定的坐标!该文档允许输入 1、2、3 或 4,每个条目都会使文本远离坐标。我可以在我的pos.vector 中使用什么值才能不进行任何更改?

谢谢!

编辑:

这是我想要做的一个例子: 一开始,我尝试:

radius <- sqrt(z/pi)    
symbols(x,y, circles = radius)
text(z,y,labels=urls)

但这会在标签中产生一些重叠,所以我尝试包含一个pos 向量:

pos.vector <- rep(3, length(urls)) #have to use 1, 2, 3, or 4 here
pos.vector[urls %in% c("victoriassecret")] <- 4
radius <- sqrt(z/pi)    
symbols(x,y, circles = z)
text(z,y,labels=urls,pos=pos.vector)

但是这种方法使我无法将其余标签保持居中,因为 pos 向量仅接受 1、2、3 或 4 作为输入。 Grr。

【问题讨论】:

  • 举个例子会有很大帮助。我的想法必须非常具体,以至于我无法弄清楚它的意图。
  • @BondedDust,举例说明。谢谢。

标签: r text plot


【解决方案1】:

通过Map 多次运行text 将到达那里,例如:

pts <- seq(0,1,length.out=4)
plot(pts,pts,pch=19)
Map(text, x=pts, y=pts, labels=letters[1:4], pos=list(4,4,NULL,1)) 

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多