2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

直播!R語言入門和ggplot2科研數(shù)據(jù)可視化入門分享!就在今晚,歡迎大家參加呀!

 weipijieli 2021-04-11

會議時間:2021/03/17 19:30-21:30 (GMT+08:00)

點擊鏈接入會,或添加至?xí)h列表:https://meeting.tencent.com/s/H9goXk0EWnqO

會議 ID:714 933 296

手機一鍵撥號入會+8675536550000,,714933296# (中國大陸)+85230018898,,,2,714933296# (中國香港)

根據(jù)您的位置撥號+8675536550000 (中國大陸)+85230018898 (中國香港)

以下是我這次分享的內(nèi)容

代碼和數(shù)據(jù)在公眾號后臺回復(fù) 20210317 直接獲得

R語言和Rstudio以及ggplot2的安裝可以參考

B站 徐洲更 視頻 可能是最好的R語言安裝指南

B站 小明的數(shù)據(jù)分析筆記本 視頻 R語言/RStudio/ggplot2的安裝過程

繪圖的第一步就是準備數(shù)據(jù)

我自己的習(xí)慣是使用excel準備數(shù)據(jù),然后另存為csv格式的文件,最后使用R語言的read.csv()函數(shù)讀入

圖片
image.png
圖片
image.png
getwd()

'D:/Jupyter/ggplot2_introduction'

library(ggplot2)

函數(shù)控制整體,參數(shù)調(diào)節(jié)細節(jié)

繪圖固定的寫法是

ggplot(data=df,aes(x=Var1,y=Var2))

接下來就是想要做什么圖,對應(yīng)疊加對應(yīng)的函數(shù)就好了
比如對應(yīng)的散點圖

ggplot(data=df,aes(x=Var1,y=Var2))+geom_point()

柱形圖

ggplot(data=df,aes(x=Var1,y=Var2))+geom_col()

1、散點圖

df1<-read.csv('example_data/scatter_plot_example.csv',header=T)
head(df1)
ggplot(data=df1,aes(x=var1,y=var2))+
geom_point()
圖片
output_13_0.png
ggplot(data=df1,aes(x=var1,y=var2))+geom_point(color='red',size=10,shape=18,alpha=0.5)
圖片
output_14_0.png
按照分類變量填充顏色、形狀
ggplot(data=df1,aes(x=var1,y=var2,color=var3,shape=var3))+geom_point(size=5)
圖片
output_16_0.png
自定義顏色形狀等
ggplot(data=df1,aes(x=var1,y=var2,color=var3,shape=var3))+
geom_point(size=5)+
scale_color_manual(values=c('steelblue''yellowgreen''violetred1'))
圖片
output_18_0.png
ggplot(data=df1,aes(x=var1,y=var2,color=var3,shape=var3))+
geom_point(size=5)+
scale_color_manual(values=c('steelblue''yellowgreen''violetred1'))+
scale_shape_manual(values=c(9,10,11))
圖片
output_19_0.png

2、氣泡圖

df2<-read.csv('example_data/bubble_plot_example.csv',header=T)
head(df2)
ggplot(data=df2,aes(x=var1,y=var2,color=var3,size=var4))+
geom_point(alpha=0.8)+
scale_size_continuous(range=c(1,50))+
theme_bw()+
theme(legend.position='none')+
ylim(0,0.4)+
scale_color_manual(values=c('steelblue''yellowgreen''violetred1'))
圖片
output_22_0.png

3、折線圖

df3<-read.csv('example_data/line_example.csv',header=T)
head(df3)
ggplot(data=df3,aes(x=time_point,y=value))+
geom_line()+
geom_point()+
geom_errorbar(aes(ymin=value-sd,ymax=value+sd),width=0.15)+
theme_bw()
圖片
output_25_0.png

4、柱形圖

df4<-read.csv('example_data/bar_plot_example.csv',header=T)
head(df4)
ggplot(data=df4,aes(x=var1,y=var2))+
geom_col()
圖片
output_28_0.png
ggplot(data=df4,aes(x=var1,y=var2))+
geom_col(color='red',fill='lightblue')
圖片
output_29_0.png
ggplot(data=df4,aes(x=var1,y=var2))+
geom_col(aes(fill=var1))+
theme_bw()+
scale_fill_manual(values = c('#008fd5','#ff2700','#77ab43','#ffd700'))+
scale_y_continuous(expand = c(0,0),limits = c(0,8))
圖片
output_30_0.png
df5<-read.csv('example_data/bar_plot_example_1.csv',header=T)
head(df5)
ggplot(data=df5,aes(x=var3,y=var2,fill=var1))+
geom_bar(stat='identity')+
theme_bw()+
scale_fill_manual(values=c('steelblue''yellowgreen''violetred1'))+
scale_y_continuous(expand = c(0,0),limits = c(0,20))
圖片
output_32_0.png
ggplot(data=df5,aes(x=var3,y=var2,fill=var1))+
geom_bar(stat='identity')+
theme_bw()+
scale_fill_manual(values=c('steelblue''yellowgreen''violetred1'))+
scale_y_continuous(expand = c(0,0),limits = c(0,20))
圖片
output_34_0.png
ggplot(data=df5,aes(x=var3,y=var2,fill=var1))+
geom_bar(stat='identity',position='dodge')+
scale_fill_manual(values=c('steelblue''yellowgreen''violetred1'))+
scale_y_continuous(expand = c(0,0),limits = c(0,10))+
theme_bw()
圖片
output_35_0.png

5、箱線圖

write.csv(ToothGrowth,file='example_data/ToothGrowth.csv',quote=F,row.names=F)
df6<-read.csv('example_data/ToothGrowth.csv',header=T)
head(df6)
table(df6$dose)
df6$dose<-factor(df6$dose,levels = c('0.5','1','2'))
ggplot(data=df6,aes(x=dose,y=len,fill=dose))+
geom_boxplot()+
scale_fill_manual(values = c('steelblue''yellowgreen''violetred1'))+
theme_bw()+
stat_boxplot(geom = 'errorbar', aes(ymin = ..ymax..),width=0.2)+
stat_boxplot(geom = 'errorbar', aes(ymax = ..ymin..),width=0.2)
圖片
output_40_0.png

6、小提琴圖

ggplot(data=df6,aes(x=dose,y=len,fill=dose))+
geom_violin()+
theme_bw()+
scale_fill_manual(values=c('steelblue''yellowgreen''violetred1'))
圖片
output_42_0.png
ggplot(data=df6,aes(x=dose,y=len,fill=dose))+
geom_violin()+
geom_boxplot(width=0.3)+
scale_fill_manual(values = c('steelblue''yellowgreen''violetred1'))+
theme_bw()+
stat_boxplot(geom = 'errorbar', aes(ymin = ..ymax..),width=0.2)+
stat_boxplot(geom = 'errorbar', aes(ymax = ..ymin..),width=0.2)
圖片
output_43_0.png

7、熱圖

df7<-read.csv('example_data/pheatmap_example_data.csv',header=T)
head(df7)
library(reshape2)
df7.1<-melt(df7,id.vars = 'gene_name')
head(df7.1)
ggplot(data=df7.1,aes(x=variable,y=gene_name,fill=value))+
geom_tile(color='black')+
theme(axis.text.x = element_text(angle=90,hjust=0.5,vjust=0.5),axis.ticks = element_blank())+
scale_fill_gradient(low = 'steelblue',high = 'violetred1')+
labs(x=NULL,y=NULL)+
geom_text(aes(label=round(value,1)))
圖片
output_50_0.png
library(patchwork)
p1<-ggplot(data=df2,aes(x=var1,y=var2,color=var3,size=var4))+
geom_point(alpha=0.8)+
scale_size_continuous(range=c(1,50))+
theme_bw()+
theme(legend.position='none')+
ylim(0,0.4)+
scale_color_manual(values=c('steelblue''yellowgreen''violetred1'))
p2<-ggplot(data=df4,aes(x=var1,y=var2))+
geom_col(aes(fill=var1))+
theme_bw()+
scale_fill_manual(values = c('#008fd5','#ff2700','#77ab43','#ffd700'))+
scale_y_continuous(expand = c(0,0),limits = c(0,8))
p3<-ggplot(data=df5,aes(x=var3,y=var2,fill=var1))+
geom_bar(stat='identity')+
theme_bw()+
scale_fill_manual(values=c('steelblue''yellowgreen''violetred1'))+
scale_y_continuous(expand = c(0,0),limits = c(0,20))
p4<-ggplot(data=df6,aes(x=dose,y=len,fill=dose))+
geom_violin()+
geom_boxplot(width=0.3)+
scale_fill_manual(values = c('steelblue''yellowgreen''violetred1'))+
theme_bw()+
stat_boxplot(geom = 'errorbar', aes(ymin = ..ymax..),width=0.2)+
stat_boxplot(geom = 'errorbar', aes(ymax = ..ymin..),width=0.2)
p1+p2+p3+p4+plot_layout(guides='collect',ncol=2,byrow = T)+plot_annotation(tag_levels = 'A')
圖片
output_56_0.png
pp<-p1+p2+p3+p4+plot_layout(guides='collect',ncol=2)
ggsave(filename = 'example_data/result_plot.pdf',
      pp,
      width=10,
      heigh=10)
ggsave(filename = 'example_data/result_plot.tiff',
      pp,
      width=10,
      heigh=10,
      dpi=300)

歡迎大家關(guān)注我的公眾號 小明的數(shù)據(jù)分析筆記本

小明的數(shù)據(jù)分析筆記本 公眾號 主要分享:1、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)、基因組學(xué)、群體遺傳學(xué)文獻閱讀筆記;3、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!

公眾號二維碼.jpg

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多