瞎折腾1
2021-03-21 本文已影响0人
123678
图片.png通过绘制一些图,用来加深和理解一些函数和语法!!!菜鸟一名,用于个人记录,比较乱。
1 使用R中的基础函数
library(reshape2)
df <- data.frame(TwoWAF=5.5,Fourwaf=1,SixWAF=1.2)
df_new <- melt(df)
barplot(df_new$value,width = c(1,1,1),ylim = c(0,7),axes=F,col = "black",border = "black",ylab = "Copy number/10ng of total RNA")
arrows(x0=0.75,y0=0,x1=0.75,y1=6,angle = 90,lwd = 3, length = 0.5)
arrows(x0=1.9,y0=0,x1=1.9,y1=1.5,lwd = 3, length = 0.5,angle = 90)
arrows(x0=3.1,y0=0,x1=3.1,y1=1.5,lwd = 3, length = 0.5,angle = 90)
axis(side = 2,labels =T)
axis(side = 4,labels = T)
points(x=c(0.75,1.9,3.1),y=c(5.6,1.5,3),col="red",pch=16)
lines(x=c(0.75,1.9,3.1),y=c(5.6,1.5,3),col="red",lwd=2)
axis(side = 1,at=c(0.75,1.9,3.1),labels = c("2WAF","4WAF","6WAF"))
mtext("FPKM", side=4, line=3, cex.lab=1,las=1, col="blue")
box()
图片.png
2 使用ggplot2
library(ggplot2)
library(reshape2)
## 创建数据集
df <- data.frame(TwoWAF=5.5,Fourwaf=1,SixWAF=1.2)
df_new <- melt(df)
p <- ggplot(df_new,mapping = aes(x=variable,y=value))+
geom_bar(stat = "identity",col="black",fill="black")+
geom_segment(aes(x=1,y=0,xend=1,yend=6),arrow = arrow(length = unit(50,"points"),angle = 90))+
geom_segment(aes(x=2,y=0,xend=2,yend=1.5),arrow = arrow(length = unit(50,"points"),angle = 90))+
geom_segment(aes(x=3,y=0,xend=3,yend=1.5),arrow = arrow(length = unit(50,"points"),angle = 90))+
geom_point(mapping = aes(x=c(1),y=c(5.6),color="red")+
geom_point(mapping = aes(x=2,y=1.5),color="red")+
geom_point(mapping = aes(x=3,y=3),color="red")+
geom_line(mapping = aes(x=c(1,2,3),y=c(5.6,1.5,3)),color="red",lwd=1)+
geom_text(mapping = aes(x=c(1,2,3),y=c(5.6,1.5,3)),label = c("5.6","1.5","3"),hjust=0,nudge_x = 0.02)+theme_test()+
theme(legend.position = "none")+
p <- p + theme_test()
p <- p + labs(x=" ",y="Copy number/10ng of total RNA")
p
图片.png
总结
1 没有解决基础函数绘制双坐标轴时怎么使两个坐标轴长度相同,标尺不同。
2 ggplot2 怎么绘制双坐标轴。
3 感觉使用Excel或者origin等更加方便。