space converted into dots in header name
1
0
Entering edit mode
3.7 years ago
Bioinfonext ▴ 470

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.

Could anyone please help how I can avoid space to dot conversion?

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

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

list.files()
A <- read.table("Spearman.count.FINAL.txt",header=T, sep="\t",check.names=F)
# 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 • 2.1k views
ADD COMMENT
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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

hello rpolicastro ,

Could you please help me how I can investigate this issue step by step?

Thanks,

ADD REPLY
0
Entering edit mode

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

ADD REPLY
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,

ADD REPLY
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,

ADD REPLY
0
Entering edit mode
3 months ago

data<- read.xlsx(path, sheet, sep.names = " ")

ADD COMMENT

Login before adding your answer.

Traffic: 1169 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6