美文网首页
R语言 -- ggplot2 学习(二)-- ‎直方图和概率密

R语言 -- ggplot2 学习(二)-- ‎直方图和概率密

作者: 生信摆渡 | 来源:发表于2020-11-05 11:37 被阅读0次

数据准备

library("ggplot2")
library("gridExtra")
library("GenomicRanges")
load("RData/hg19_CGI.RData") # hg19_CGI

widths = width(hg19_CGI)
data = data.frame(widths)

axis.text = theme(axis.text.x = element_text(size = 20),
                  axis.text.y = element_text(size = 20))

直方图1

p1 <- ggplot(data, aes(x = widths)) + theme_bw()
p1 <- p1 + geom_histogram(binwidth = 200, colour = "#dd1c77", fill= "white")
p1 <- p1 + labs(x = "", y = "", title = "Whole CGI Histplot")
p1 <- p1 + theme(plot.title = element_text(size = 25, face = "bold")) + axis.text
print(p1)

直方图2

subdata = data.frame(widths = data[data[, 1] <= 5000,])
p2 <- ggplot(subdata, aes(x = widths)) + theme_bw()
p2 <- p2 + geom_histogram(binwidth = 100, colour = "#dd1c77", fill= "white")
p2 <- p2 + labs(x = "", y = "", title = "CGI width low 5000 Histplot")
p2 <- p2 + theme(plot.title = element_text(size = 25, face = "bold")) + axis.text
print(p2)

直方图 + 概率密度图

# hist + density plot
p3 <- ggplot(subdata, aes(x = widths)) + theme_bw()
p3 <- p3 + geom_histogram(aes(y = ..density..),
                          binwidth = 100, 
                          colour = "#dd1c77",
                          fill= "white")
p3 <- p3 + labs(x = "", y = "", title = "CGI width low 5000 Hist+Density Plot")
p3 <- p3 + theme(plot.title = element_text(size = 25, face = "bold"))
p3 <- p3 + geom_density(alpha= 0.2, colour = "#3182bd", fill = "white",size = 2) + axis.text
print(p3)

一页多图

grid.arrange(p1, arrangeGrob(p2, p3, ncol = 2), nrow=2) 

相关文章

网友评论

      本文标题:R语言 -- ggplot2 学习(二)-- ‎直方图和概率密

      本文链接:https://www.haomeiwen.com/subject/ejpovktx.html