R 在点打印面板中禁用未使用的标签

R 在点打印面板中禁用未使用的标签,r,lattice,R,Lattice,我有以下数据框 ds <- data.frame(iso2c=as.factor(c(rep("AR",3),rep("BR",3),rep("DE",3),rep("US",3))), region= as.factor(c(rep("LATAM",6),rep("DEVELOPED",6))), year= rep(c(1979,1989,1999),4), value= c( 47.0 , 28

我有以下数据框

   ds <- data.frame(iso2c=as.factor(c(rep("AR",3),rep("BR",3),rep("DE",3),rep("US",3))),

             region= as.factor(c(rep("LATAM",6),rep("DEVELOPED",6))),

             year= rep(c(1979,1989,1999),4),

             value= c( 47.0 , 28.6,  20.8, 100.0,  64.2,  35.4,  16.0 ,  9.0,   5.5,  15.6,  11.6,   8.6))                 )
问题是,作为iso2c分区的区域,我在每个面板中有两个空行(发达国家的AR和BR是空的,美国和拉丁美洲的DE是空的)

更改面板功能以删除该面板中未使用的级别(请参阅以下代码)不起作用

dotplot(iso2c~value | region, data=ds, groups=year,pch=19,col="dark blue",cex=1.3,ylab="country",layout=c(1,2),
     panel=function(x,y,...) {
       panel.dotplot(x,droplevels(y),...)    
    },

)

有没有办法抑制面板中未使用的级别?

您可以使用
点图
函数中的
缩放
参数指示您希望y轴自由缩放。这将仅包括每个面板中存在的级别:

dotplot(iso2c~value | region, data=ds, groups=year,pch=19,
    col="dark blue",cex=1.3,ylab="country",layout=c(1,2),
    scales = list(y = list(relation = "free")))

在这种情况下,可能最好将输入数据展平。
dotplot(iso2c~value | region, data=ds, groups=year,pch=19,
    col="dark blue",cex=1.3,ylab="country",layout=c(1,2),
    scales = list(y = list(relation = "free")))