密码子偏向性的ENC-plot

使用R语言的ggplot2包绘制密码子偏向性分析中的ENC-plot

将数据整理到excel中,第一列GC3s,第二列ENC值,然后复制到剪切板,通过read.table()函数读入

df <- read.table("clipboard",header=T)

自定义理论ENC计算函数
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)
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
  geom_point(df,aes(x=GC3s,y=ENC))+xlim(0,1)+
  ylim(0,70)+labs(x="GC3s",y="ENC")+theme_bw()
28.png

到这一步有人遇到报错Error: `mapping` must be created by `aes(),具体是什么原因我不知道,对应着把geom_point(df,)改成geom_point(data=df)就不会有这个报错了

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)
df<-data.frame(GC3s=sample(seq(0,1,by=0.05),15),
               ENC=sample(1:60,15))
绘图
library(ggplot2)
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()
image.png

如果想为散点添加不同的颜色,自己想到的解决办法是为数据集添加一列因子变量,用来给散点映射不同的颜色

我的数据集中有59个数据
d <- c(LETTERS,letters,paste(LETTERS[1:7],letters[1:7],sep=""))
df$class<-d
ggplot(df1,aes(x=A,y=B))+geom_line(size=1)+
  geom_point(df,aes(x=GC3s,y=ENC,color=class))+xlim(0,1)+
  ylim(0,70)+labs(x="GC3s",y="ENC")+theme_classic()+
  theme(legend.position="none")
29.png
ggplot(df,aes(x=GC3,y=ENC))+geom_point(color=df$class)+
  geom_text_repel(data=subset(df,ENC>46.8&ENC<46.82),
                  direction="x",nudge_y=-10,nudge_x=0.1,
                  segment.colour = "green",
                  arrow=arrow(length=unit(0.02,"npc"),type="open",
                            ends="first"),
                  segment.size = 1,label="Punica granatum")+
  geom_line(data=df1,aes(x=A,y=B),size=1)+ylim(0,70)+theme_classic()+
  labs(x="GC3S",y="ENC")
小知识点

R语言中中的 colors() 函数可以将所有颜色列出来
生成渐变色使用函数 colorRampPalette(),用法colorRampPalette(c("red","green"))(10)

参考文献
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容