原文鏈接:R語(yǔ)言繪圖 | 最全的云雨圖繪制教程
關(guān)于《R語(yǔ)言繪圖專欄》
關(guān)于《R語(yǔ)言繪圖專欄》棒呛,此專欄基于
R語(yǔ)言
繪制圖形蒙兰。每個(gè)圖形我們會(huì)提供對(duì)應(yīng)的R代碼
、數(shù)據(jù)
和文本
文檔睛藻。此系列將會(huì)是一個(gè)長(zhǎng)期更新的系列。
注意:若是你加入我們社群,則直接在社群中獲得筑舅。
本期教程
2023年教程總匯
Code
- 加載所需R包
library(ggrain)
library(ggplot2)
- 加載數(shù)據(jù)
iris
- 繪制基礎(chǔ)云雨圖
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_rain(rain.side = 'l')
ggplot(iris, aes(x = 1, y = Sepal.Length, fill = Species)) +
geom_rain(alpha = .5)
給散點(diǎn)添加顏色
ggplot(iris, aes(1, Sepal.Width, fill = Species, color = Species)) +
geom_rain(alpha = .6,
boxplot.args = list(color = "black", outlier.shape = NA)) +
theme_classic() +
scale_fill_brewer(palette = 'Dark2') +
scale_color_brewer(palette = 'Dark2')
將圖形進(jìn)行翻轉(zhuǎn),使用
coord_flip()
ggplot(iris, aes(Species, Sepal.Width, fill = Species)) +
geom_rain(alpha = .5) +
theme_classic() +
scale_fill_brewer(palette = 'Dark2') +
guides(fill = 'none', color = 'none') +
coord_flip()
- 兩兩進(jìn)行配對(duì)陨舱,使用線條連線
事例數(shù)據(jù)整理
set.seed(42) # the magic number
iris_subset <- iris[iris$Species %in% c('versicolor', 'virginica'),]
iris.long <- cbind(rbind(iris_subset, iris_subset, iris_subset),
data.frame(time = c(rep("t1", dim(iris_subset)[1]), rep("t2", dim(iris_subset)[1]), rep("t3", dim(iris_subset)[1])),
id = c(rep(1:dim(iris_subset)[1]), rep(1:dim(iris_subset)[1]), rep(1:dim(iris_subset)[1]))))
# adding .5 and some noise to the versicolor species in t2
iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t2"] <- iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t2"] + .5 + rnorm(length(iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t2"]), sd = .2)
# adding .8 and some noise to the versicolor species in t3
iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t3"] <- iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t3"] + .8 + rnorm(length(iris.long$Sepal.Width[iris.long$Species == 'versicolor' & iris.long$time == "t3"]), sd = .2)
# now we subtract -.2 and some noise to the virginica species
iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t2"] <- iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t2"] - .2 + rnorm(length(iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t2"]), sd = .2)
# now we subtract -.4 and some noise to the virginica species
iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t3"] <- iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t3"] - .4 + rnorm(length(iris.long$Sepal.Width[iris.long$Species == 'virginica' & iris.long$time == "t3"]), sd = .2)
iris.long$Sepal.Width <- round(iris.long$Sepal.Width, 1) # rounding Sepal.Width so t2 data is on the same resolution
iris.long$time <- factor(iris.long$time, levels = c('t1', 't2', 't3'))
iris.long[iris.long$time %in% c('t1', 't2'),]
.......繼續(xù)訪問(wèn)下文................
往期部分文章
1. 最全WGCNA教程(替換數(shù)據(jù)即可出全部結(jié)果與圖形)
2. 精美圖形繪制教程
3. 轉(zhuǎn)錄組分析教程
4. 轉(zhuǎn)錄組下游分析
小杜的生信筆記 翠拣,主要發(fā)表或收錄生物信息學(xué)教程,以及基于R分析和可視化(包括數(shù)據(jù)分析游盲,圖形繪制等)误墓;分享感興趣的文獻(xiàn)和學(xué)習(xí)資料!!
本文由mdnice多平臺(tái)發(fā)布