本节的内容为:查看数据基本信息,包括最小值,最大值,中位数,上下四分位数,以及字符型变量的频数。用到的新函数summary()。
简单粗暴,直接上代码:
# 包载入,才能够使用
library(ggplot2)
# 赋值变量
filename <- "Lesson-03/Encode_HMM_data.txt"
# 数据导入
# Select a file and read the data into a data-frame
my_data <- read.csv(filename, sep="\t", header=FALSE)
# 小部分数据的查看
head(my_data)
# 变量的重新命名
# Rename the columns so we can plot things more easily without looking up which column is which
names(my_data)[1:4] <- c("chrom","start","stop","type")
# At any time, you can see what your data looks like using the head() function:
head(my_data)
# 绘制图片
# Now we can make an initial plot and see how it looks
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
# 以上是第一节课中的内容,下面才是一点新的知识
#查看我们的数据到底有多大
# We can see how big our data is:
dim(my_data)
# summary()函数可以查看整个数据的基本统计参数
# We can ask our data some questions:
summary(my_data)
#当然也是可以查看单个变量的统计参数
# We can break these down by column to see more:
summary(my_data$chrom)
summary(my_data$type)
summary(my_data$start)
summary(my_data$stop)
# 这里是一种添加新变量的方法,可以学习,size是新的变量,这算是一个新的知识点。
# We can even make a new column by doing math on the other columns
my_data$size = my_data$stop - my_data$start
# 查看一下是否有新的变量
# So now there's a new column
head(my_data)
# 基本统计:平均数,标准差,中数,最大值,最小值
# Basic statistics:
summary(my_data$size)
mean(my_data$size)
sd(my_data$size)
median(my_data$size)
max(my_data$size)
min(my_data$size)
# 下一节课需要解决的内容:可以发现x轴的染色体位置是乱的,字体不能适配,名字错误,类型太多。
# Let's think about the issues and in the next lesson we will learn how to deal with them
ggplot(my_data,aes(x=chrom,fill=type)) + geom_bar()
# 1) Chromosomes in the wrong order, and the "chr" prefixes don't fit on the x-axis
# 2) Too many types
# 3) Bad names for the types
网友评论