这次使用ggplot2画片段分布图,一起学习的小伙伴加个好友,互相学习共同进步
数据是自己分析的到的片段数据
data <- read.table("fragment.length.txt", header = F)
# # 设置插入片段长度的阈值,过滤掉太长的片段
length_cutoff <- 1200
fragment <- data$V1[data$V1 <= length_cutoff]
head(fragment)
df <- data.frame(fragment)
head(df)
# 利用直方图统计频数分布,设置柱子个数
breaks_num <- 500
res <- hist(df, breaks = breaks_num, plot = FALSE)
# 添加坐标原点
plot(x = c(0, res$breaks),
y = c(0, 0, res$counts) / 10^2,
type = "l", col = "red",
xlab = "Fragment length(bp)",
ylab = expression(Normalized ~ read ~ density ~ 10^2),
main = "Sample Fragment sizes")
fragment.png
下面的参考代码来自:
Histogram with density in ggplot2 | R CHARTS (r-charts.com)
# install.packages("ggplot2")
library(ggplot2)
# Histogram with Fragment length
ggplot(df, aes(x = fragment)) +
geom_histogram(aes(y = ..density..),
colour = 1, fill = "white") +
geom_density(lwd = 1, colour = 4,
fill = 4, alpha = 0.25)
image.png
网友评论