R:如何在每个点阵xyplot中设置两个标题(主标题和副标题?)>

问题描述 投票:0回答:1

我在R数据框中有一个样本数据:

d <- read.table(text = 
"Grp     Var    Col1  Col2    Col3    Sub_grp
grp_1   8      46.8  50.0   50.6    A
grp_1   16     95.6  47.4   48.0    A
grp_1   24     45.1  45.6   46.4    A
grp_1   32     68.8  44.3   58.2    A
grp_1   40     44.6  52.2   44.3    A
grp_1   48     86.5  42.2   68.6    A
grp_2   40     63.2  95.6   63.0    B
grp_2   60     66.7  67.5   65.6    B
grp_2   80     69.6  70.7   67.9    B
grp_2   100    71.9  73.4   69.3    B
grp_2   120    73.8  75.7   48.0    B
grp_3   500    51.9  50.0   50.5    C
grp_3   1000   65.5  53.0   53.4    C
grp_3   5000   61.2  99.0   59.9    C
grp_3   10000  80.1  63.0   62.8    C
grp_3   30000  25.9  33.8   14.2    C
  ", header=T
)

下面的代码可以正常工作,并像这样绘制数据:

xyplot(
  Col1 + Col2 + Col3 ~ Var | Grp,
  data=d,
  superpose=T,
  as.table=TRUE,
  col=c("#cc0000","#008000", "#0073e6"),
  lwd=1.5, ylim = c(0,120),
  ylab = list(label=expression("My Values"), fontsize=15),
  xlab = list(label="Var",fontsize=15),
  key=list(
    text  = list(c("Col1", "Col2", "Col3")),
    lines = list( lwd=1.5, col=c("#cc0000","#008000", "#0073e6")),
    corner = c(1, 0),
    x = 0.90, 
    y = 0.17),
  par.settings = list(strip.background=list(col="white")),
  scales=list(cex=1.2,x=list(relation="free")),
  type=c("l","g")
)

plot

现在,我想在每张图中添加Sub_grp列作为副标题,这样它应该有两个标题(Grp和Sub_grp),而不是一个标题(grp)。我在相关问题之一中尝试了建议here,并更改了行:

Col1 + Col2 + Col3 ~ Var | Sub_grp+Grp

在上面的代码中,我的情节看起来像这样。关于如何解决此问题的任何建议?

messy plot :(

我在我的R数据帧中有一个样本数据:d

r lattice
1个回答
0
投票

由于您的Grp和Sub_grp映射为1:1,所以可以尝试

© www.soinside.com 2019 - 2024. All rights reserved.