Manipulating axis titles in ggpairs (GGally)

后端 未结 3 615
礼貌的吻别
礼貌的吻别 2021-01-31 05:50

I\'m using the code below to generate the following chart.

# Setup
data(airquality)

# Device start
png(filename = \"example.png\", units = \"cm\", width = 20, h         


        
3条回答
  •  醉话见心
    2021-01-31 06:47

    Caveat: not a complete answer but perhaps suggests a way to approach it. You can do this by editing the grid objects.

    # Plot in current window
    # use left to add space at y axis and bottom for below xaxis
    # see ?print.ggpairs
    print(pairs.chrt, left = 1, bottom = 1)
    
    # Get list of grobs in current window and extract the axis labels
    # note if you add a title this will add another text grob, 
    # so you will need to tweak this so not to extract it
    g <- grid.ls(print=FALSE)
    idx <- g$name[grep("text", g$name)]
    
    # Rotate yaxis labels
    # change the rot value to the angle you want
    for(i in idx[1:6]) {
            grid.edit(gPath(i), rot=0, hjust=0.25, gp = gpar(col="red"))
     }
    
    # Remove extra ones if you want
    n <- ncol(airquality)
    lapply(idx[c(1, 2*n)], grid.remove)
    

    enter image description here

提交回复
热议问题