profile = "Pos;h3k27ac;ctcf;enhancer;h3k4me3;polII
-5000;8.7;10.7;11.7;10;8.3
-4000;8.4;10.8;11.8;9.8;7.8
-3000;8.3;10.5;12.2;9.4;7
-2000;7.2;10.9;12.7;8.4;4.8
-1000;3.6;8.5;12.8;4.8;1.3
0;3.6;8.5;13.4;5.2;1.5
1000;7.1;10.9;12.4;8.1;4.9
2000;8.2;10.7;12.4;9.5;7.7
3000;8.4;10.4;12;9.8;7.9
4000;8.5;10.6;11.7;9.7;8.2
5000;8.5;10.6;11.7;10;8.2"
profile_text <- read.table(text=profile, header=T, row.names=1, quote="",sep=";")
profile_text_rownames <- row.names(profile_text)
profile_text$xvariable = rownames(profile_text)
data_m <- melt(profile_text, id.vars=c("xvariable"))
# 就是这一句,会经常用到
data_m$xvariable <- factor(data_m$xvariable, levels=profile_text_rownames, ordered=T)
# geom_line设置线的粗细和透明度
p <- ggplot(data_m, aes(x=xvariable, y=value,color=variable,group=variable)) + geom_line(size=1, alpha=0.9) + theme(legend.position=c(0.85,0.2)) + theme(axis.text.x=element_text(angle=45,hjust=1, vjust=1))
# stat_smooth
#p <- ggplot(data_m, aes(x=xvariable, y=value,color=variable,group=variable)) + stat_smooth(method="auto", se=FALSE) + theme(legend.position=c(0.85,0.2)) + theme(axis.text.x=element_text(angle=45,hjust=1, vjust=1))
p