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

时间:2018-11-13 09:23:18

标签: r plot ggally ggpairs

具有ggpairs函数,如何将较低的切面范围限制为例如x和y是0.5?

library(GGally)

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

ggpairs(xy)

enter image description here

1 个答案:

答案 0 :(得分:2)

您需要定义一个绘图功能(一个方面)。您可以在这里疯狂使用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