r-corrplot package with pa, как я могу увеличить размер участков - PullRequest
0 голосов
/ 06 июня 2019

Я хочу отобразить в corrplots используя функцию par () R. Это работает, однако графики очень малы, и заголовок обрезается. Я хочу увеличить размер графиков, а также переместить заголовок ближе к реальному графику.

Я пытался поиграть с mar, а также с fig из par (). Я могу заставить его работать

Ниже приведен полный код для воспроизведения проблемы

######################## Preparation / Loading #####################
#Load Library
library(lavaan)
library(Hmisc)
library(grid)
library(gridExtra)
library(corrplot)

flattenCorrMatrix <- function(cormat, pmat) {
  ut <- upper.tri(cormat)
  data.frame(
    row = rownames(cormat)[row(cormat)[ut]],
    column = rownames(cormat)[col(cormat)[ut]],
    cor  =(cormat)[ut],
    p = pmat[ut]
  )
}

######################## Constants #########################
centers <- list("Center1","Center2")

######################## Function to draw Corrplot #########################
draw.corrplot <- function(colorsheme,title = "Undefined"){
  ######## Options of corrplot ########
  # Method = "number" displaying numbers instead of circles
  corrplot(res2$r, type="upper", order="original", main = title, mar = c(0.1, 0.1, 0.1, 0.1), cl.offset = 5,
           p.mat = res2$P, sig.level = 0.05, insig = "blank", col = colorsheme, method = "square",tl.col = "black", tl.cex = .75)
  col.text = "black"
}

#################  Setting Colorsschemes for the Heat Map #################
col1 <- colorRampPalette(c( "#00007F","blue","#007FFF","cyan", "white",
                            "yellow","#FF7F00","red", "#7F0000"))
col2 <- colorRampPalette(c("blue","white","red"))


######################## Case & Variable Selection #########################
# select Variables: all sum scores + filter variable
colnames <- c("Zentrum","another_way_to_long_varname","just_more_long_vars","furhterLongVarname",
              "ok_thats_really_one_over_the_top","thesixthvariable","another","eightVariable","somevar","another")
mydata <- data.frame(replicate(10,sample(0:1,1000,rep=TRUE)))
colnames(mydata) <- colnames
mydata
#allow multiple plots
par(mfrow=c(1,2))

# Select Cases by center and draw corrplot

for (i in c(0,1)){
  print(i)
  filtered <- mydata [which(mydata$Zentrum==i),]
  filtered$Zentrum <- NULL
  res2 = rcorr(as.matrix(filtered))
  a = flattenCorrMatrix(res2$r, res2$P)
  #creating a custom title consisting of
  #   Name of Center + N obersvations
  mtitle <- paste(centers[i+1],"( N =",nrow(filtered),")")
  draw.corrplot(col1(1000),mtitle)
}
#a
#grid.table(a)

# dev.off()
# ?corrplot

1 : 2 Corrplots using parhttps://ibb.co/nMpbWV5

...