简体   繁体   English

带两行标题的条带 - R 格子图

[英]Strip with two lines title - R lattice plot

I'm having difficulties to write correctly a strip name in a lattice plot.我很难在格子图中正确写出条带名称。 Here is a data example:下面是一个数据示例:

    resposta<-rnorm(90)
    preditor1<-rep(rep(c("a","b"),each=15),3)
    preditor2<-rep(c("sp1","sp2","sp3"),each=30)

And I'm doing the following plot:我正在做以下情节:

    library(lattice)
    bwplot(resposta~preditor1|preditor2,layout=c(3,1),
           strip=strip.custom(
               factor.levels=c(
                   expression(atop(italic("P. paradoxa"),"outra info")),
                   expression(atop(italic("H. raniceps"),"outra info")),
                   expression(atop(italic("P. azurea"),"outra info")))
           ),
           par.settings=list(layout.heights=list(strip=2.5))
           )

My question is, are there a way to get a smaller space between the species name and "outra info".我的问题是,有没有办法在物种名称和“外部信息”之间获得更小的空间。 This problem started because, as the title are species names, they need to be in italic, but I also need to add some extra information on the title, and this should not be in italic.这个问题的开始是因为标题是物种名称,它们需要斜体,但我还需要在标题上添加一些额外的信息,这不应该是斜体。 I saw on Google the possibility to use atop inside an expression to get 2 lines of text, but I get a too big space between the species name and the next line.我在 Google 上看到了在expression使用atop来获取 2 行文本的可能性,但是我在物种名称和下一行之间得到了太大的空间。 I would like them to be closer together, but I don't know if it is possible, and if so, how to do it.我希望他们能走得更近,但我不知道这是否可能,如果可能,该怎么做。

Does anyone know how to skip lines in the strip name, keeping the expression for the italics but not make too much space between names?有谁知道如何跳过条带名称中的行,保留斜体的表达式但不要在名称之间留出太多空格? It's not so bad on the plot, but when I use tiff() to save to a image with a greater size, the strip names are missing some parts, basically due to the distance between the lines, I think.情节上还不错,但是当我使用tiff()保存到更大尺寸的图像时,我认为条带名称缺少某些部分,这主要是由于线条之间的距离。

As explained by Duncan Murdoch via the R-help mailing list , this problem cannot be easily solved without employing atop (which results, in your particular case, in undesirably large line spacing).正如 Duncan Murdoch 通过R-help mailing list解释的那样,如果不使用atop就不能轻易解决这个问题(这会导致在您的特定情况下,行间距过大,这是不希望的)。 However, you could achieve your goal manually by navigating to the respective strip panels using downViewport and subsequently inserting the two lines of text separately using grid.text .但是,您可以通过导航到相应的带板手动实现自己的目标downViewport ,随后分别使用插入文本的两行grid.text

## create plot with invisible strip labels
bwplot(resposta ~ preditor1 | preditor2, layout = c(3, 1),
       par.settings = list(layout.heights = list(strip = 2.5)), 
       par.strip.text = list(col = "transparent")
)

## add species labels
lbl <- c("P. paradoxa", "H. raniceps", "P. azurea")

for (i in 1:3) {
  # navigate to i-th strip
  vp <- paste0("plot_01.strip.", i, ".1.vp")
  downViewport(vp)

  # add first and second line of text
  grid.text(bquote(italic(.(lbl[i]))), vjust = ifelse(i %in% 1:2, 0, -.25))
  grid.text("outra info", vjust = 1.1)

  # navigate to top level
  upViewport(0)
}

paneled_plot

Also, make sure to have a look at current.vpTree() which returns the current panel structure of your trellis graph.另外,请务必查看current.vpTree() ,它返回格状图的当前面板结构。 Once you redefine the panel layout, add another group, etc., you will most likely have to adjust the creation of the panel name to navigate to (object "vp") inside the for loop.一旦您重新定义面板布局、添加另一个组等,您很可能必须调整面板名称的创建以导航到for循环内的(对象“vp”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM