太长,读不下去了
可以使用较低级别对绘图进行注释
网格
图形功能。在这种情况下,请执行以下操作:
library(grid)
seekViewport("plot_01.legend.top.vp")
grid.text("Hello", x=0, y=unit(1,"npc") + unit(0.4, "lines"), just=c("left", "bottom"),
gp=gpar(cex=1.6))
光栅Vis
和其他
格子木架
-基于的包使用
网格
图形系统,而不是其基本图形系统
mtext()
是一部分。
这里,使用
网格
,是我在视口左上角上方0.4行的位置添加文本的方式(技术
网格
术语),其中打印上边距图。
-
首先,找到相关视口的名称。
library(grid)
levelplot(r)
grid.ls(viewport=TRUE, grobs=FALSE) ## Prints out a listing of all viewports in plot
快速扫描返回的列表
grid.ls()
打开名为
plot_01.legend.top.vp
,看起来很有前途。如果您想检查它是否正确,可以围绕它绘制一个矩形,如下所示(使用视口的完整路径):
grid.rect(vp = "plot_01.toplevel.vp::plot_01.legend.top.vp",
gp = gpar(col = "red"))
-
然后,使用
网格
非常灵活的坐标系,将所需的文本放在视口左上角的正上方。
ll <- seekViewport("plot_01.legend.top.vp")
grid.text("Hello", x = 0, y = unit(1,"npc") + unit(0.4, "lines"),
just = c("left", "bottom"),
gp = gpar(cex=1.6))
upViewport(ll) ## steps back up to viewport from which seekViewport was called