我想使用R的par()功能在corrplots上显示。它可以正常工作,但是绘图很小,标题被切断。我想增加地块的大小,并将标题移到更接近实际地块的地方。
我尝试过mar和par()中的fig。我很高兴让它起作用
下面是重现该问题的完整代码
######################## 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