1

我正在使用lsmipfrom lsmeans来绘制我的模型,

 library(lsmeans)

 PhWs1 <- lsmip(GausNugget1, Photoperiod:Ws ~ Month, 
                ylab = "Observed log(number of leaves)", xlab = "Month",
                main = "Interaction between Photoperiod and Water stress over the months (3 photoperiods)",
                par.settings = list(fontsize = list(text = 15, points = 10)))

但我无法在互联网上获得有关如何处理图例位置、大小、标题等的建议。我曾经trellis.par.get()查看参数,但找不到与我的问题相关的参数。从图中可以看出,图例应为“Photoperiod*Ws”,但 Ws 不可见。

在此处输入图像描述

4

1 回答 1

5

我看到两个可能互补的替代方案来解决这个问题。第一个是创建一个完全自定义的图例,并将其传递给(主要基于)的key论点。这是一个示例,以澄清我的观点。xyplotlsmip?lsmip

## default trellis point theme
trellis_points <- trellis.par.get("superpose.symbol")

## create customized key
key <- list(title = "Some legend title",                  # legend title
            cex.title = 1.2, 
            x = .7, y = .9,                               # legend position
            points = list(col = trellis_points$col[1:2],  # points
                          pch = trellis_points$pch[1:2],  
                          cex = 1.5),                     
            text = list(c("A", "B"), cex = .9))          # text

## create results and extract lattice plot
d <- lsmip(warp.lm, wool ~ tension, plotit = FALSE,
           main = "Some figure title", key = key)

p <- attr(d, "lattice")
p

lsmip

如您所见,设置自定义图例可让您修改图例的所有不同组成部分 - 包括标签、文本和符号大小、图例间距等。更深入地了解其中描述的key参数,?xyplot其中描述了各种修改选项细节。

现在,如果您有一个较长的图例标题并且您不想将图例包含在绘图区域内,您还可以定义单独的视口,从而允许图例在右边距占据更多空间。请注意使用网格功能从单个图形组件中update删除最初创建的图例以及随后的组装。p

## remove legend from figure
p <- update(p, legend = NULL)

## assemble figure incl. legend 
library(grid)

png("plot.png", width = 14, height = 10, units = "cm", res = 300)
grid.newpage()

## add figure without legend
vp0 <- viewport(x = 0, y = 0, width = .75, height = 1, 
                just = c("left", "bottom"))
pushViewport(vp0)
print(p, newpage = FALSE)

## add legend
upViewport(0)
vp1 <- viewport(x = .7, y = 0, width = .3, height = 1, 
                just = c("left", "bottom"))
pushViewport(vp1)
draw.key(key, draw = TRUE)
dev.off()

lsmip2

于 2016-03-21T10:25:19.487 回答