我也出现了这个问题,请问楼主解决没?一行一行试过后发现 col=c("red","blue")) 应该是这里错了,但不知道怎么改
知道怎么改了。。。哈哈
main=paste(gene,"(p", pValue ,")",sep="") )
倒数第二个)是中文格式,改成英文格式就ok了
#install.packages("survival")
>
> setwd("C:\\Users\\Lenovo-lxp\\Desktop\\colonTME\\geneSurvival") #工作目录(需修改)
>
> library(survival)
> rt=read.table("clinicalExp.txt",header=T,sep="\t",check.names=F) #读取文件
> rt$futime=rt$futime/30 #如果以月为单位,除以30;以年为单位,除以365
> outTab=data.frame()
>
> for(gene in colnames(rt[,4:ncol(rt)])){
+ a=rt[,gene]<=median(rt[,gene])
+ diff=survdiff(Surv(futime, fustat) ~a,data = rt)
+ pValue=1-pchisq(diff$chisq,df=1)
+ outTab=rbind(outTab,cbind(gene=gene,pvalue=pValue))
+
+ fit <- survfit(Surv(futime, fustat) ~ a, data = rt)
+ summary(fit)
+
+ if(pValue<0.05){
+ if(pValue<0.001){
+ pValue="<0.001"
+ }else{
+ pValue=round(pValue,3)
+ pValue=paste0("=",pValue)
+ }
+ pdf(file=paste(gene,".survival.pdf",sep=""),
+ width=6,
+ height=6)
+ plot(fit,
+ lwd=2,
+ col=c("red","blue"),
+ xlab="Time (year)",
+ #mark.time=T,
+ ylab="Survival rate",
+ main=paste(gene,"(p", pValue ,")",sep="") )
> legend("topright",
+ c("High","Low"),
+ lwd=2,
+ col=c("red","blue"))
Error in strwidth(legend, units = "user", cex = cex, font = text.font) :
plot.new has not been called yet
> dev.off()
null device
1
> }
错误: 意外的'}' in " }"
> }
错误: 意外的'}' in "}"
> write.table(outTab,file="survival.xls",sep="\t",row.names=F,quote=F)