代码之家  ›  专栏  ›  技术社区  ›  orizon

组合点阵图在x轴上产生空间隙

  •  0
  • orizon  · 技术社区  · 11 年前

    我正在尝试使用晶格创建一个组合条形图和xyplot,其中x轴由两个图共享。

    require(lattice)
    require(latticeExtra)
    dd <- data.frame(Year = factor(1990:1999), Count = 0:9, Size = 9:0)
    p1 <- barchart(Count ~ Year, data = dd, horizontal = FALSE)
    p2 <- xyplot(Size ~ Year, data = dd)
    c(p1,p2, x.same = TRUE, layout = c(1,2))
    

    enter image description here

    这幅图不令人满意,因为 latticeExtra 合并绘图时,在x轴上增加1和10的额外间隙。这些差距不会出现在各个组成图上。

    如何从x轴上删除1和10?

    正如我所指出的,我在这种特殊情况下的问题可以通过删除 x.same 论点然而,这并不是一个通用的解决方案,只因为我的例子不令人满意。下面显示了一个改进的示例。

    dd1 <- data.frame(Year = factor(1990:1999), Count = 0:9)
    p1 <- barchart(Count ~ Year, data = dd1, horizontal = FALSE)
    
    
    dd2 <- data.frame(Year = factor(1991:2000), Size = 0:9)
    p2 <- xyplot(Size ~ Year, data = dd2, type = "o")
    p2
    

    正在删除 x.相同 产量:

    c(p1,p2, layout = c(1,2))
    

    enter image description here

    该图不令人满意,因为它有两个x轴。

    (我问了一个较早但不同的问题 question 试图解决这个问题)。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Kevin Wright    11 年前

    也许你需要从两个图的相同因子水平开始。

    # Using factors
    
    dd1 <- data.frame(Year = factor(1990:2000), Count = c(0:9,NA))
    p1 <- barchart(Count ~ Year, data = dd1, horizontal = FALSE)
    
    
    dd2 <- data.frame(Year = factor(1990:2000), Size = c(NA,0:9))
    p2 <- xyplot(Size ~ Year, data = dd2, type = "o")
    p2
    
    c(p1,p2, layout = c(1,2)) # works