space converted into dots in header name
0
0
Entering edit mode
3 months ago
Bioinfonext ▴ 330

I am using the below code to read a tab-delimited file which has spaces in the header name and these spaces converted into dots while plotting with corrplot.

library(vegan)
library(phyloseq)
library(ggplot2)
library(magrittr)
library(dplyr)
library(reshape2)
library(RColorBrewer)

library(corrplot)
library("PerformanceAnalytics")
library("Hmisc")
library(psych)

list.files()
# Convert the first column to be row names
B <- A[, -1]
C <- data.frame(B, row.names=A$Sample) M = as.matrix(C) #View(M) #--------------------Calculate correlation matrix and p-value matrix------------------------# #-------------------------------------spearman---------------------------------------------# cor_5 <- rcorr(as.matrix(M),type=c("spearman")) r_mat <- cor_5$r
p_mat <- cor_5\$P
# Extract the r and p (only Euka vs Bac, no inner correlations e.g. bac-bac)
r = r_mat[1:9,10:191]
p = p_mat[1:9,10:191]
# Only consider the positive correlation (r>0)
r_0 = r*(r> 0 )


Many thanks

R Rstudio microbiome • 336 views
0
Entering edit mode

A general solution for keeping spaces is to put individual header names in quotation marks. Don't know if that will be helpful with this package.

0
Entering edit mode

At what step in your code are they getting converted from spaces to dots?

0
Entering edit mode

hello rpolicastro ,

Thanks,

0
Entering edit mode

Use, 'check.names = FALSE'' in read.twble function.

0
Entering edit mode

Nothing is working from all the above suggestions. I am not sure at which step, spaces are converted in dots.

Thanks,

0
Entering edit mode

Thank you all. I have resolved this problem by substituting dot with space in the end.

colnames(r_0) <- gsub("\\.", " ", colnames(r_0))


Thanks,