Quick code to run some correlations on a sample table

library(tidyverse)
library(readxl)

df<-read_xlsx("table.xlsx")
df2<-df %>% 
    mutate(Sample=paste0(reactor,"_",day),
           S=make.names(S)) %>% 
    select(S,Sample,cov) %>% 
    pivot_wider(id_cols = Sample, 
                names_from = S,
                values_from = cov) %>%
    column_to_rownames("Sample")

The code below perform the spearman correlations and generate a single dataframe with all the information: P values, adjusted P values and r values.

dr<-Hmisc::rcorr(as.matrix(df2),type = "spearman" )

rowCol <- expand.grid(rownames(dr$P), colnames(dr$P))
labs <- rowCol[as.vector(upper.tri(dr$P,diag=F)),]
P <- cbind(labs, dr$P[upper.tri(dr$P,diag=F)])

dr$padj<-p.adjust(P$P,method = "BH")

P<- cbind(P, dr$padj)
colnames(P) <- c("Row","Col","P","r","padj")

and plotting

ggplot(P %>% filter(P<0.05), aes(x=Row,y=Col,col=r,size=-log10(padj)))+
  geom_point()+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90))+
  scale_colour_viridis_c(option = "C")

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →