【问题标题】:When dragging the graphical device the labels don't move with the plot in R?拖动图形设备时,标签不会随 R 中的图移动?
【发布时间】:2023-03-29 11:53:01
【问题描述】:

以下是28个地块的图框:

par(mfcol = c(7, 4), mar = rep(.1, 4), oma = rep(7, 4))

invisible(lapply(1:28, plot, t = "n", xaxt = "n", yaxt = "n"))

要将标签添加到上述绘图框架的 y 轴 (side = 2),我执行以下操作:

mid.y = seq(grconvertY(0 + (1 / 14), "nic"), grconvertY(1 - (1 / 14), "nic"), l = 7)

gap.y = sort(c(mid.y[-length(mid.y)] + diff(mid.y)[1L] / 2, grconvertY(0:1, "nic")))

l = c('1/10', '1/3', '1', '3', '10', '30', '100', '> 100000')
mtext(l, side = 2, at = gap.y, line = 22, cex = .9, font = 2, las = 1) # notice `line = 22

问题

标签位置完美。但是,如果我将图形设备向右或向左拖动,标签不会随情节移动?如何修复标签以随情节移动(请看以下 2 张图片)?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    这是一个复杂的绘图案例。因此,为了完全控制使用text() 而不是mtext()。这样您就不需要依赖line = 参数,这会导致您在上面的问题中描述的问题。

    基于上述 R 代码的解决方案:

    text(grconvertX(0, "nic"), gap.y, l, xpd = NA, adj = 1, cex = 1.3, font = 2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2020-01-06
      相关资源
      最近更新 更多