ggplot2几种常见的散点图

1,散点图

结果示例:


image.png

输入文件示例:


image.png

代码:

library(ggplot2)
data<-read.table("ch_num_per_sample.stat.add_age.cancer",head=T,sep='\t')
p<-cor.test(data$CH.number,data$Age,method="spearman")
ggplot(data) + geom_point(aes(Age, CH.number), alpha=0.25, shape=16,stat = "identity",position = "identity") + xlim(0, 120) + ylim(0, 35) + coord_fixed() + xlab('Age') + ylab('CH number')+annotate(geom="text",x=91,y=32.5,label=paste('Spearman Correlation ( corr=',round(p$estimate[[1]],4),';p=',p$p.value,' )',sep=""),colour='black',size=2.3)
ggsave('Age_CH.number_point.png',dpi = 1080)

2,散点图+拟合曲线+折线图

结果示例:


image.png

输入文件示例:


image.png

代码:

library(ggplot2)
data<-read.table("age_stat.age.each.cancer.xls",header=T,sep="\t")
pdf("CH_age_cor.pdf", width=12, height=6)
ggplot(data,aes(age, Percent)) + geom_point( alpha=0.25, shape=16,stat = "identity",position = "identity") + xlab('Age') + ylab('Percent (%)') +stat_smooth(method="lm") +geom_line(aes(age, Percent,group=Cancer,color=Cancer),alpha=0.55)+scale_x_continuous(breaks=c(1,2,3,4,5,6,7),labels=c("<=40","40-50","50-60","60-70","70-80","80-90","90-100"))
dev.off()

3,散点图+拟合曲线+部分点标注

结果示例:


image.png

输入文件示例:


image.png

代码:

library(plyr)
library(ggplot2)
library(ggrepel)
data<-read.table("carry_ratio.stat.xls",header=T,sep="\t",row.names=1)
p<-cor.test(data$tissue_ratio,data$plasma_ratio)
sub1<-data[data$tissue_ratio>data$plasma_ratio,]
sub2<-data[data$tissue_ratio

你可能感兴趣的:(ggplot2几种常见的散点图)