How to show only the lower triangle in ggpairs?

前端 未结 1 1842
鱼传尺愫
鱼传尺愫 2020-12-11 05:36

I am using ggpairs to make a pairs plot, but I only want to display the lower triangle. I can make the diagonal and upper triangle blank, but cannot make them g

相关标签:
1条回答
  • 2020-12-11 06:10

    The ggpairs object can be edited. The bulk of the object is list of plots. The unwanted plots can be removed from this list and the other elements of the ggpairs object modified to match.

    Here is a function that will do this

    gpairs_lower <- function(g){
      g$plots <- g$plots[-(1:g$nrow)]
      g$yAxisLabels <- g$yAxisLabels[-1]
      g$nrow <- g$nrow -1
    
      g$plots <- g$plots[-(seq(g$ncol, length(g$plots), by = g$ncol))]
      g$xAxisLabels <- g$xAxisLabels[-g$ncol]
      g$ncol <- g$ncol - 1
    
      g
    }
    
    library("GGally")
    g <- ggpairs(iris[, 1:4], 
                 lower  = list(continuous = "points"),
                 upper  = list(continuous = "blank"),
                 diag  = list(continuous = "blankDiag")
         )
    
    gpairs_lower(g)
    

    0 讨论(0)
提交回复
热议问题