將多個基因的cds用下面的網(wǎng)址獲得結(jié)果
https://galaxy.pasteur.fr/?tool_id=toolshed.pasteur.fr%2Frepos%2Fkhillion%2Fcodonw%2Fcodonw%2F1.4.4&version=1.4.4&__identifer=zwhtdsoycw9
##選擇Calculate Effective Number of Codons和Calculate GC of silent 3rd codon posit
結(jié)果如圖,一共三列

image.png
修改為以下格式

image.png
這個結(jié)果用ggplot繪制保存為文件code.txt
ENC<-function(x){
return(2 + x + 29/(x^2+(1-x)^2))
}
x <- seq(0,1,by=0.005)
y <- ENC(x)
df1<-data.frame(A=x,B=y)
library(ggplot2)
df <- read_delim("/your-path/code.txt",
"\t", escape_double = FALSE, trim_ws = TRUE)
##只用前兩列繪圖
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_bw()
###到這一步有人遇到報錯Error: `mapping` must be created by `aes(),具體是什么原因我不知道,對應(yīng)著把geom_point(df,)改成geom_point(data=df)就不會有這個報錯了。

image.png
##將第三列映射為顏色
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
theme(legend.position="none")

image.png
添加標(biāo)簽
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
geom_text(data=df,aes(x=GC3s,y=ENC,color=gene,label=gene))
theme(legend.position="none")

image.png
存在重疊看不起
這里使用ggrepel包中的geom_text_repel函數(shù),只需要將geom_text換成geom_text_repel即可。
library(ggrepel)
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
geom_text_repel(data=df,aes(x=GC3s,y=ENC,color=gene,label=gene))
theme(legend.position="none")

image.png
###繪制GC3s圖
ENC<-function(x){
return(2 + x + 29/(x^2+(1-x)^2))
}
x <- seq(0,1,by=0.005)
y <- ENC(x)
df1<-data.frame(A=x,B=y)
library(ggplot2)
df <- read_delim("~/yt/20230106_baimaike/0105_YC_hifi/mito_assemble_script/0314_comparate-mito/6-code/txt",
"\t", escape_double = FALSE, trim_ws = TRUE)
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_bw()
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
geom_text(data=df,aes(x=GC3s,y=ENC,color=gene,label=gene))
theme(legend.position="none")
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
geom_text_repel(data=df,aes(x=GC3s,y=ENC,color=gene,label=gene))
theme(legend.position="none")
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
geom_point(data=df,aes(x=GC3s,y=ENC,color=gene))+xlim(0,1)+
ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
geom_text_repel(data=df,aes(x=GC3s,y=ENC,color=gene,label=gene),fontface="bold", color="black")
theme(legend.position="none")