代码之家  ›  专栏  ›  技术社区  ›  Roman LuÅ¡trik

如何在ggpairs函数中定义面轴限制

  •  1
  • Roman LuÅ¡trik  · 技术社区  · 6 年前

    有一个 ggpairs 函数,如何将下刻面的范围限制为0.5(x和y)?

    library(GGally)
    
    xy <- data.frame(matrix(runif(4 * 1000), ncol = 4))
    
    ggpairs(xy)
    

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  3
  •   Roman LuÅ¡trik    6 年前

    您需要定义一个绘制(一个方面)的函数。你可以和 ggplot 在这里。见 this similar question

    limitRange <- function(data, mapping, ...) { 
      ggplot(data = data, mapping = mapping, ...) + 
        geom_point(...) + 
        geom_smooth(method = "lm", se = FALSE) +
        scale_y_continuous(limits = c(0, 0.5)) +
        scale_x_continuous(limits = c(0, 0.5)) 
    }
    
    # This is how you specify which part of the image will be
    # plotted using your function.
    ggpairs(xy, lower = list(continuous = limitRange))
    

    enter image description here