密碼子偏好性繪圖

將多個基因的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")

參考http://www.itdecent.cn/p/acb2736bccc2

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容