结合 2 个具有不同 y 轴的点图会导致在 x 轴上重叠

combining 2 dotplots with different y axis leads to overlap on x axis

我正在尝试使用 latticelatticeExtra 包组合 2 个点图,但我发现 x 轴上的数据组在组合图中重叠。这是一个可重现的例子:

首先,我创建了 2 个可重现的数据集并将它们融合,使它们变长而不是变宽:

require(lattice)

df1 <- data.frame(Treatment = rep(c("B", "C"), each = 6),
                  LocB = sample(1:100, 12), 
                  LocC = sample(1:100, 12))

dftwo <- data.frame(Treatment = rep(c("A"), each = 6),
                    LocA = sample(1:100, 6))

dat.reprod1 <- melt(df1, id.vars = 'Treatment')

dat.reprod2 <- melt(dftwo, id.vars = 'Treatment')

然后我为每个数据集创建一个点图:

dotreprod1 <- dotplot(value ~ Treatment, data = dat.reprod1,
                      par.strip.text = list(cex = 3),
                      cex = 2)

dotreprod2 <- dotplot(value ~ Treatment, data = dat.reprod2,
                      par.strip.text = list(cex = 3), col = "orange",
                      cex = 2)

然后我将它们组合起来,为 dotreprod2 添加一个新的 Y 轴:

require(latticeExtra)
doubleYScale(dotreprod1, dotreprod2, add.ylab2 = TRUE, use.style = F)

不幸的是,"A" 组合图的 x 轴上没有空间,因此橙色点与蓝色点重叠。是否可以在 X 轴上创建 space,使 "A"、"B" 和 "C" 彼此相邻并且点不重叠?

在两个单独的图中,将 x 变量指定为 factor 和组合数据的 levels,并设置 drop.unused.levels = FALSE

dotreprod1 <- dotplot(value ~ factor(Treatment, levels = LETTERS[1:3]),
                      data = dat.reprod1,
                      drop.unused.levels = FALSE)

dotreprod2 <- dotplot(value ~ factor(Treatment, levels = LETTERS[1:3]),
                      data = dat.reprod2,
                      col = "orange",
                      drop.unused.levels = FALSE)

doubleYScale(dotreprod1, dotreprod2, add.ylab2 = TRUE, use.style = FALSE)