P-Value Representation Using corrplot() - r

The code I have written produces the image attached here. I'm wanting to make the asterisks smaller in size, but I am not sure how to do this. Also, is it possible to represent different levels of significance with the number of asterisks (*=0.1, **=0.05, ***=0.001). Thanks in advance. My code and figure are below as well.
alpha_corr <- cor(Schiller_Numerical, method = "pearson")
alpha_p <- cor.mtest(alpha_corr, method = "pearson", conf.level = 0.95, exact = FALSE)
corrplot(
cor(alpha_corr, method = "pearson"),
tl.col = "black",
tl.srt = 60,
method = 'square',
order = 'hclust',
type = 'lower',
diag = TRUE,
tl.cex = 1,
title = "Heatmap For All Data",
mar=c(0,0,2,0),
p.mat = alpha_p$p,
sig.level = 0.05,
insig = "label_sig") `

You can find all the useful parameters you required in the corrplot() documentation : https://www.rdocumentation.org/packages/corrplot/versions/0.92/topics/corrplot
You need to modify pch.cex to adjust asdterisk size, and sig.level to specify the signficance levels as a vector.
data(mtcars)
alpha_p <- cor.mtest(mtcars, method = "pearson", conf.level = 0.95, exact = FALSE)
corrplot(
cor(mtcars, method = "pearson"),
tl.col = "black",
tl.srt = 60,
method = 'square',
order = 'hclust',
type = 'lower',
diag = TRUE,
tl.cex = 1,
title = "Heatmap For All Data",
mar=c(0,0,2,0),
p.mat = alpha_p$p,
sig.level = c(0.001,0.05,0.1),
insig = "label_sig",
pch.cex=1)

Related

How do I add line plots/distributions to a histogram in R?

The following is my code, and I would like to get the dpear and ppear plots to appear on the histogram, just as I have done with the density curve, but I am running into some issues trying to do that. If someone could point me in the right direction, that would be great!
library(readr)
library(fitdistrplus)
library(moments)
library(PearsonDS)
library(ggplot2)
newdata <- read_csv("Downloads/newctdata - Sheet1.csv")
data <- rpearson(1000, moments = c(mean = 0.5205263, variance = 0.3940497, skewness = 1.747905, kurtosis = 5.706342))
ppar <- pearsonFitML(data)
print(unlist(ppar))
print(unlist(pearsonFitM(moments = empMoments(data))))
pIpars <- list(a = 0.44883385, b = 2.22621271, location = 0.04565093, scale = 3.20779382)
t <- seq(0, 2.5, by = 0.1)
dpearsonI(t, params = pIpars)
dpear <- plot(t, dpearsonI(t, params = pIpars), type = "l")
ppearsonI(t, params = pIpars)
dpear <- plot(t, ppearsonI(t, params = pIpars), type = "l")
hist(newdata$Mean, prob = TRUE, xlab = "Mean Duration of Asymptomatic Infection in Women", ylab = "Frequency", col = "steelblue", breaks = 12, cex.main = 1.3, cex.axis = 1.5, cex.lab = 1.5)
lines(density(newdata$Mean), col = "tomato", lwd = 4)

How can I merge two different graphics from corrplot

I generated two different graphics which have different labels, is it possible two merge it?
library(corrplot)
par(mfrow=c(1,2))
col<- colorRampPalette(c("#78CB65","#EBF6DF","#AEDAAA"))
corrplot(as.matrix(samp4), is.corr = FALSE, type = 'lower', method = 'color', addCoef.col = 'black', number.cex=0.50,
col=col(11),
tl.col = "black",
tl.cex = 0.8,
title = "OrthoANI")
corrplot(as.matrix(ddh2), is.corr = FALSE, type = 'upper', method = 'color', addCoef.col = 'black', number.cex=0.50,
col=col(11),
tl.col = "black",
tl.cex = 0.8,
title = "ddh")
I would like two merge it like this
I tried making only one data from ddh2 and samp4, but the problem is that the threshold and values are different, so the label has to be different
thanks

Is it possible to add a grouping label to a corrplot?

Is it possible to add a label that applies to a few variables in a corrplot? This is an example of what I'm after. In that case it is the word "Petals" on the y-axis.
Below is the code to make the rest of the plot.
library(corrplot)
library(Hmisc)
iris_c <- iris[, c(1:4)]
test <- rcorr(as.matrix(iris_c))
corrplot(test$r, type="lower", order= "original",
p.mat = test$P, sig.level = 0.01, insig = "blank",
col= colorRampPalette(c("blue","white", "red"))(100), tl.col = 'black', cl.ratio = 0.8, tl.srt = 45, diag = FALSE, method = "square")
You can use title() to adjust axis labels, which is what you're looking for here. After running your code above, just run:
title(ylab = "Petals")

ggcorrplot2 shows different significance asterisks

does anybody have an idea why ggcorrplot2 shows different significance asterisks than ggcorrplot? Very confusing to me.
https://github.com/caijun/ggcorrplot2
data(mtcars)
ct <- corr.test(mtcars)
corr <- ct$r
p.mat <- ct$p
ggcorrplot(corr, type= "lower", p.mat = p.mat,
insig = "label_sig", sig.lvl = c(0.05, 0.01, 0.001),show.diag=F)
ggcorrplot.mixed(corr, upper = "number", lower = "circle", p.mat = p.mat,
insig = "label_sig", sig.lvl = c(0.05, 0.01, 0.001))
Update: Ok I think I figured it out finally. Its because corr.test() writes a unsymmetric matrix of p.values.
"Entries above the diagonal are adjusted for multiple tests."
I fixed this with p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)].
Furthermore if you want to use the adjusted p.Values it is important to mirror the triangle above the diagonal of the p.Value matrix. If you need the unadjusted p.Values it is the lower triangle that needs to be mirrored (code needs to be changed accordingly).
data(mtcars)
cor.matrix <- corr.test(mtcars,method = "spearman", adjust = "BH", alpha = 0.05, ci = F)
corr <- cor.matrix[["r"]]
p.mat <- cor.matrix[["p"]]
p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)] #to get only the adjusted p.Values symmetrically over the plot
p.mat[lower.tri(p.mat, diag = T)] <- 1 #to set the lower triangle to 1
corrplot.mixed(corr, order= "original",mar=c(0,0,2,0), tl.col = 'black', p.mat = p.mat, insig = "label_sig", sig.level = c(.001, .01, .05), pch.cex=1.5, tl.cex = .8, number.font=2, number.cex=0.8)
data(mtcars)
cor.matrix <- corr.test(mtcars,method = "spearman", adjust = "BH", alpha = 0.05, ci = F)
corr <- cor.matrix[["r"]]
p.mat <- cor.matrix[["p"]]
p.mat[lower.tri(p.mat)] <- t(p.mat)[lower.tri(p.mat)] #to get only the adjusted p.Values symmetrically over the plot
p.mat[lower.tri(p.mat, diag = T)] <- 1 #to set the lower triangle to 1 (this way the asterisks wont be displayed on this part of the graph)
corrplot.mixed(corr, order= "original",mar=c(0,0,2,0), tl.col = 'black', p.mat = p.mat, insig = "label_sig", sig.level = c(.001, .01, .05), pch.cex=1.5, tl.cex = .8, number.font=2, number.cex=0.8)

Reduce whitespace in corrplot in R

I have a 1 row 2 column plot which I need to insert into a report. When I insert the plot I notice there's a large white area around both correlation plots. Is there an argument in the corrplot function to reduce this? I've read here about using knitr hook functions to crop pdfs but that a bridge too far for my coding capabilities. I've messed around with the par() arguments such as omi and mai but when I export the image to TIFF I still get a huge white space area.
My code so far looks as follows, please note this is hacked together from various sources and dputs to both correlation matrices can be found here and here:
col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))
par(mfrow=c(1,2),omi=c(0,0,0,0),mai=c(0.1,0.1,0.1,0.1))
corrplot(LX0088U21A1_24hrCor, method = "color", col = col(200),
type = "upper", order = "original", number.cex = 0.85,
addCoef.col = "black", # Add coefficient of correlation
tl.col = "black", tl.srt = 90,
number.digits = 1,
# Text label color and rotation
# hide correlation coefficient on the principal diagonal
diag = FALSE,
#title = "Intraday Correlation LX0088U21A1",
mar=c(0,0,1,0))
legend(0.5,5,ncol = 1, cex = 1.5,legend = "(a)", box.lwd = 0, box.col = "white")
corrplot(LX0088U09A3_24hrCor, method = "color", col = col(200),
type = "upper", order = "original", number.cex = 0.75,
addCoef.col = "black", # Add coefficient of correlation
tl.col = "black", tl.srt = 90,
number.digits = 1,
# Text label color and rotation
# hide correlation coefficient on the principal diagonal
diag = FALSE,
#title = "Intraday Correlation LX0088U09A3",
mar=c(0,0,1,0))
legend(0.5,5,ncol = 1, cex = 1.5,legend = "(b)", box.lwd = 0, box.col = "white")
Any help is greatly appreciated.

Resources