R语言报错记录
2020-06-29 本文已影响0人
蜡笔小生信
ggplot2包
用以下代码画图报错
p+geom_point(aes(x=disp,y=mpg,shape=gear),size=4)
Error: A continuous variable can not be mapped to shape
解决办法
gear被当做数值型变量了,可以转换成shape=as.factor(gear)
R批量读取与写入
rm(list = ls())
setwd("C:\\Users\\TAY\\Desktop\\yr")
file_names<- list.files("C:\\Users\\TAY\\Desktop\\yr")
path <- c("C:\\Users\\TAY\\Desktop\\yr\\")
listyr = list()
for (i in 1:length(file_names)) {
name<-gsub(".CSV","",file_names[i])
listyr[[i]] <- assign(name,read.csv(paste0(path,file_names[i]),header = TRUE, stringsAsFactors = FALSE))
}
filenames <- gsub(".csv",file_names)
filenames <- paste0("gene",file_names)
filenames <- paste0(file_names,".txt")
for (v in 1:length(listyr)){
result1<- merge(listyr[[v]],al,by="Symbol")
write.table(result1,filenames[v],sep = "\t", row.names = F,quote=F)
}
file_names<- list.files("C:\\Users\\TAY\\Desktop\\buru\\")
path <- c("C:\\Users\\TAY\\Desktop\\buru\\")
list1 <- list()
for (i in 1:length(file_names)) {
name<-gsub(".txt","",file_names[i])
list1[[i]] <-assign(name,read.delim(paste0(path,file_names[i]),sep= "\t",header = TRUE, stringsAsFactors = FALSE))}
puru <- read.delim("geneko.txt",sep = "\t",header = T)
colnames(puru)[4] <- "Gene"
pu <- read.csv("gene.description.CSV")
for (v in 1:length(list1)) {
name1 <-gsub(".txt","",file_names[v])
b <- merge(list1[[v]],puru,by = "Gene")
a <- merge(b,pu,by="Gene_id")
write.csv(a,paste0(name1,".csv"),row.names = F)
}