生信技能树 R语言 初级作业题目(下)

2019-06-16  本文已影响0人  Ashu

在RStudio输出图片的方法:


图片输出步骤1.png
图片输出步骤2.png
boxplot(SraRunTable$MBases, main = "boxplot of MBases")
boxplot of MBases.jpeg
plot(fivenum(SraRunTable$MBases), main = "fivenum of MBases")
fivenum of MBases.jpeg
plot(hist(SraRunTable$MBases), main = "hist of MBases")
hist of MBases.jpeg
plot(density(SraRunTable$MBases,na.rm=T), main = "density of MBases")
density of MBases.jpeg
title = sample$Title 
class(title)
#run
> title = sample$Title
> class(title)
[1] "character"
plate = unlist(lapply(title,function(x){ x
  strsplit(x,'_')[[1]][3]
}))
table(plate)
#run
> table(plate)
plate
0048 0049 
 384  384 
t.test(SraRunTable$MBases~plate)
#run

    Welch Two Sample t-test

data:  SraRunTable$MBases by plate
t = 2.3019, df = 728.18, p-value = 0.02162
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 0.1574805 1.9831445
sample estimates:
mean in group 0048 mean in group 0049 
          13.08854           12.01823 
boxplot(m$MBases~plate)
MBases~plate.jpeg
typeof(plate)
#run
> typeof(plate)
[1] "character"

在这里卡了很久,在运行之前喜欢清空,结果运行变量e老报错,先运行前面的变量SraRunTable,sample,m后再运行。

e = m[,c("MBases","Title")]
e$plate = plate
hist(e$MBases,freq = F, breaks = "sturges")
hist of e$MBases.jpeg
plot(density(e$MBases,na.rm=T))
density of e$MBases.jpeg
library(ggplot2)
suppressMessages(library(ggplot2)) e$plate = plate
e$num=c(1:768)
colnames(e)
#run
> colnames(e)
[1] "MBases" "Title"  "plate"  "num"
ggplot(e,aes(x=plate,y=MBases)) + geom_boxplot()
#`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot of e MBases.jpeg
ggplot(e,aes(x=MBases)) + geom_histogram(fill="lightblue",colour="grey") + facet_grid (plate ~ .)
ggplot of histogram.jpeg
ggplot(e,aes(x=MBases,fill=plate))+geom_histogram()
ggplot of histogram 2.jpeg
ggplot(e,aes(y=MBases,x=num)) + geom_point() + stat_density2d(aes(alpha=..density..),
 geom = "raster",contour = F)+ facet_grid(plate ~ .)
Ggplot of density.jpeg
ggplot(e,aes(x=MBases,fill=plate))+geom_density()
ggplot of density 2.jpeg
suppressMessages(library(ggpubr))
ggboxplot(e, x="plate", y="MBases", color = "plate", palette = "aaas",add = "jitter") + stat_compare_means(method = "t.test")
Ggboxplot of e.jpeg
gghistogram(e, x="MBases", fill = "plate",palette = c("#f4424e", "#41a6f4"))
#Warning message:
Using `bins = 30` by default. Pick better value with the argument `bins`.
gghistogram of e.jpeg
ggdensity(e, x="MBases", fill = "plate", , color = "plate", add = "mean",palette = c(
  "#f4424e", "#41a6f4"))
ggdensity of e.jpeg
data <- e[sample(nrow(e),384),][,c(3,1,2)]
str(data)
#run
> data <- e[sample(nrow(e),384),][,c(3,1,2)]
> str(data)
'data.frame':   384 obs. of  3 variables:
 $ plate : chr  "0049" "0048" "0049" "0049" ...
 $ MBases: int  3 16 5 2 8 14 25 11 16 7 ...
 $ Title : chr  "SS2_15_0049_J6" "SS2_15_0048_N2" "SS2_15_0049_M5" "SS2_15_0049_N24" ...

课程分享

生信技能树全球公益巡讲

https://mp.weixin.qq.com/s/E9ykuIbc-2Ja9HOY0bn_6g

B站公益74小时生信工程师教学视频合辑

https://mp.weixin.qq.com/s/IyFK7l_WBAiUgqQi8O7Hxw

招学徒:

https://mp.weixin.qq.com/s/KgbilzXnFjbKKunuw7NVfw

上一篇 下一篇

猜你喜欢

热点阅读