R corrplot: weird error with significance test - r

I am desperately trying to solve an issue with R corrplot. I have a 10 * 22 matrix that I would like to visualize using corrplot, but adding significance level just produces crosses outside of the boarder of the visual. I could produce correlation plots without significant tests using the following script:
corrplot(matrix, method = "circle",tl.cex=0.4, tl.col = "black", col = color(10))
However, the following script produces crosses outside of the border of the visual:
res1 <- cor.mtest(corredata, conf.level = .95)
corrplot(matrix, p.mat = res1$p, method = "circle", tl.cex=0.6, tl.col = "black",
col = color(10), sig.level = 0.05, insig = "pch")
Is there something wrong with my code?

Related

P-value significance levels in corrplot

I would like to show not only * when a correlation is significant but the different significance levels, e.g. * for p < .05, ** for p < 0.01 and so on.
I calculated a correlation and the p-value-function as follows:
Corr_Emo <- cor(df_Emo[, 3:11], method = "pearson")
pval <- psych::corr.test(df_Emo[3:11], adjust="none")$p
and plotted my corrplot
corrplot(Corr_Emo,
method="color", col=col(200),
tl.srt = 45,
tl.cex = 1.0,
tl.col = "black",
diag=FALSE,
type="upper", #order="hclust",
title=title,
addCoef.col = "black",
# Combine with significance
p.mat = pval, sig.level = 0.05, insig="label_sig", pch.cex = 1.5,
mar=c(0,0,1,0)
)
but of course it only signs a correlation * if it is significant in any way.
I am not that good in R so I don't know exactly how to modify pval with psych::corr.test in a way that it shows me the different levels of *.
Could anybody help me here?
Thank you very much in advance!

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")

Rstudio - corrplot highlight ony high correlation values in the plot

I'm trying to highlight only correlation values <-.7 and >0.7 in my correlation plot, but I'm getting trouble on it.
I have this data like this
Parn_Spt_comp_2
And I did a Pearson correlation with this code:
par_spt.pearson2 <-cor(Parn_Spt_comp_2[,3:14], method = "pearson")
par_spt.pearson2
After I plotted the values with the code below:
corrplot(par_spt.pearson2, method="color", addCoef.col = "black" ,type="lower", sig.level = 0.05,
number.cex = 1.2, tl.col = "black",tl.cex = 1.25, number.font = 1, tl.srt = 0, tl.offset = 0.3, pch=19, addgrid.col="black",col=colorRampPalette(c("white","coral3"))(10), cl.cex=1.25, mar = c(0,0,0,0))
And display it:
But I would like to show only correlation values in the interval mentioned above, and the values >-0.7 and <0.7 do not appear in the plot. I tried many things, but it still not working. I would be grateful if you help me.
Thank you in advance!

How can I display the p-value in a correlation Plot in the right size?

I have plotted a correlation matrix resulting from the function "rcorr" with "corrplot". Everything comes out fine so far, except one thing. I would like to display the p-value for either all, or for at least the cells, where the p-value is higher than the previously defined significance level of 0.005. The "insig" function does display the the p-values for the cells with p<sig, but I can't change the size of the plotted numbers. I tried to use any of the given arguments of the "corrplot" function, but it has no effect of the size of the p-value text. Does anyone know how I could change the size and how I can control the position of the p-values in each cell?
Here is the code I am using:
my_data <- FS[,2:27]
# Mark the insignificant coefficients according to the specified p-value significance level
library(corrplot)
library(Hmisc)
FScor <- rcorr(as.matrix(my_data[,1:25],method = c("spearman")))
M_Konz <- FScor$r
p_matK <- FScor$P
CorrKonz <- corrplot(M_Konz, type = "upper", order = "hclust", insig = "p-value",
p.mat = p_matK, sig.level = 0.005,
tl.cex = 0.7,tl.col = "black",
title = "")
Unfortunately corrplot does not give you direct control over the size of the p-values, but you can get it by setting the graphics parameter directly. You did not provide reproducible data so I'll use an example from the corrplot vignette. Your code has a problem with the rcorr line since method= is not an argument of as.matrix or rcorr.
M <- rcorr(as.matrix(mtcars), type="spearman")
Mr <- M$r
Mp <- M$P
oldp <- par(cex=.75)
Mcorr <- corrplot(Mr, type = "upper", order = "hclust", insig = "p-value",
p.mat = Mp, sig.level = 0.005, tl.cex = 1.25, tl.col = "black",
cl.cex=1.25, title = "")
par(oldp)
The mtcars data frame is included with R. We set the graphical parameter cex to .75 (default is 1) and then increase the size of the variable labels with tl.cex and the legend labels with cl.cex. After drawing the plot we reset the default graphics parameters.

Attempting to add confidence ellipses to NMDS gives error "Error in cov.wt(X, W) : 'x' must contain finite values only"

I am attempting to add 95% confidence ellipse to an NMDS plot using the vegan package and function "ordiellipse" and keep getting the same error message. The ordination looks like this:
microcosm_nmds <- ordinate(physeq = physeq_bac1, method = "NMDS", distance = "bray")
plot_ordination(
physeq = physeq_bac1,
ordination = microcosm_nmds,
color = "day",
shape = "location",
title = "NMDS of Microcosm bacterial Communities"
) +
scale_color_manual(values = c("red", "#ffae19",
"#4daf4a", "#1919ff", "darkorchid3", "magenta")
) +
geom_point(aes(color = day), alpha = 0.7, size = 4) +
geom_point(colour = "grey90", size = 1.5)
The code for the ellipse I am trying to use is:
ordiellipse(microcosm_nmds, groups = "day", display = "sites", kind = "sd", conf = 0.95, col = "black", w = NULL)
When doing this, I keep getting an error that says "Error in cov.wt(X, W) : 'x' must contain finite values only" and I'm not sure why. There are no NAs or missing values in the data, and the ordination works fine. I can only guess it has something to do with sample weights? But I'm not sure. Any help at all would be much appreciated.
Thanks!

Resources