如何在格子中标记面板 [英] How to label panels in lattice

查看:66
本文介绍了如何在格子中标记面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,您肯定已经遇到过,但让我头疼不已...

here is a simple problem that surely you already come across, but is giving me a big headache...

我有一个像这样的数据框:

I have a dataframe like this:

set.seed(3)
mydata <- data.frame(var = rnorm(100,20,1),
                     temp = sin(sort(rep(c(1:10),10))),
                     subj = as.factor(rep(c(1:10),5)))

我需要为每个主题制作一个散点图,这不是问题,但是... 我想要的是替换晶格中的条带,并为每个图添加标签. 我设法用下面的代码来做到这一点,但我仍然不满意...

and I need to make a scatter plot for each subj, not a problem, but... what i want is to replace the strips from the lattice and add a label to each plot. I manage to do this with the following code, but I'm still not happy...

xyplot(var ~ temp | subj, 
       data = mydata,
       strip=FALSE,
       panel = function(x, y,...) {
               panel.xyplot(x, y,...)
               panel.text(1,21,labels=which.packet())
               }) 

最后一点...我堆积的地方是...如何在每个面板中打印字母而不是数字.我想将面板命名为a,b,c ...等等.

The last bit...where i got stacked...is how to print letters instead of numbers in each panel. I would like to call the panels a,b,c... and so on.

任何建议... 非常感谢 哑光

Any suggestions... Many thanks matteo

推荐答案

您几乎明白了.如果需要字母,则用panel.number()索引letters:

You almost got it. If you need letters, then index letters with panel.number():

xyplot(var ~ temp | subj, 
   data = mydata,
   strip=FALSE,
   panel = function(x, y,...) {
           panel.xyplot(x, y,...)
           panel.text(1,21,labels=letters[panel.number()])
           }) 

您还可以在面板函数中定义另一个字符向量,并将其与该索引架构一起使用.

You can also define another character vector inside your panel function and use this indexing schema with it.

这篇关于如何在格子中标记面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆