首页 > 解决方案 > 将文本添加到指定位置的绘图

问题描述

我想为下图中的每一行添加标签: 在此处输入图像描述

a <- 1:2000
b <- a - a[1]

plot(1, type = "n", xlab = "Scale parameter", ylab = "No. of days", xlim = c(0, 90), ylim = c(0, 150))
shape.range <- seq(from = 2, to = 10, by = 1)
scale.range <- seq(from = 10, to = 70, by = 1)

for(sh in seq_along(shape.range)){

sh.ref <- shape.range[sh]

 for(sc in seq_along(scale.range)){

   sc.ref <- scale.range[sc]
   p <-  1 - exp(-(b/sc.ref)^sh.ref)
   p.l <- which.max(p >= 0.97)

   points(sc.ref,   p.l, cex = 0.5, pch = 19)
#  text(80, # how to insert the value of y here such that the label ends up at the end of the each line, labels = paste0(sh.ref))
  }
}

标签: rtextlegend

解决方案


并不是所有的东西都需要是 ggplots。基础图形有时更容易调整。

只需在您的代码后添加这些行。

text(20,100,"Text left")
text(60,20,"Text right")

在此处输入图像描述


推荐阅读