r中的ggpairs:如何(1)调整轴值,以及(2)在两行(或更多行)上拆分长变量名

r中的ggpairs:如何(1)调整轴值,以及(2)在两行(或更多行)上拆分长变量名,r,ggplot2,ggally,ggpairs,R,Ggplot2,Ggally,Ggpairs,关于在r中使用ggpairs绘图,我有两个问题: (1) 我有一些不可避免的长变量名,在ggpairs的默认输出中没有完整显示。如何调整ggpairs以使整个名称可见(例如,标签可以拆分为多行,或以45度角显示,等等) (2)如何为单个变量的轴限制设置自定义范围 例如,下面的代码给出了下面的图: library(GGally) set.seed(99) really_long_variable_name_1 <- round(runif(50, 0, 1), 2) really_lon

关于在
r
中使用
ggpairs
绘图,我有两个问题:

(1) 我有一些不可避免的长变量名,在ggpairs的默认输出中没有完整显示。如何调整ggpairs以使整个名称可见(例如,标签可以拆分为多行,或以45度角显示,等等)

(2)如何为单个变量的轴限制设置自定义范围

例如,下面的代码给出了下面的图:

library(GGally)

set.seed(99)

really_long_variable_name_1 <- round(runif(50, 0, 1), 2)
really_long_variable_name_2 <- round(runif(50, 0, 0.8), 2)
really_long_variable_name_3 <- round(runif(50, 0, 0.6), 2)
really_long_variable_name_4 <- round(runif(50, 0, 100), 2)

df <- data.frame(really_long_variable_name_1, 
                    really_long_variable_name_2,
                    really_long_variable_name_3,
                    really_long_variable_name_4)

ggpairs(df) 
库(GGally)
种子集(99)

真正的_long_variable_name_1首先,您可以修改列名以将u识别为分隔点:

cleanname = function(x,lab="\n"){
  sapply(x, function(c){ 
    paste(unlist(strsplit(as.character(c) , split="_")),collapse=lab)
  })
  }

colnames(df) = cleanname(colnames(df))

#Using your function
custom_range <- function(data, mapping, ...) { 
  ggplot(data = data, mapping = mapping, ...) + 
    geom_point(...) + 
    scale_x_continuous(limits = c(0, 1)) +
    scale_y_continuous(limits = c(0, 1)) 
}
接下来,为每个绘图编制索引并覆盖现有比例。我相信有一种更干净的方式来编码

myplot[4,1]= myplot[4,1] + scale_y_continuous(limits  = c(0,100))
myplot[4,2]= myplot[4,2] + scale_y_continuous(limits  = c(0,100))
myplot[4,3]= myplot[4,3] + scale_y_continuous(limits  = c(0,100))


myplot
myplot = ggpairs(df,
        lower = list(continuous = custom_range)) +
 theme(strip.text.x = element_text(size = 6, angle = 45)) 
myplot[4,1]= myplot[4,1] + scale_y_continuous(limits  = c(0,100))
myplot[4,2]= myplot[4,2] + scale_y_continuous(limits  = c(0,100))
myplot[4,3]= myplot[4,3] + scale_y_continuous(limits  = c(0,100))


myplot