所有資料來源于生信技能樹
1. 常用的可視化R包

image.png
(1)Base

image.png

image.png
高級函數(shù)是出圖,低級函數(shù)是添磚加瓦
2.ggplot2語法

image.png
入門級模板
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
2.1屬性設(shè)置

image.png
geom_point(mapping = aes(x = displ, y = hwy), color = "blue")
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy),
size = 5, # 點(diǎn)的大小5mm
alpha = 0.5, # 透明度 50%
shape = "※") # 點(diǎn)的形狀

image.png
2.2映射

image.png

顏色設(shè)置方法

image.png

自行指定映射的顏色

R語言顏色
搜索16禁止顏色代碼,替代下圖中的紅框

image.png

image.png

color是邊框顏色,fill是內(nèi)心顏色
2.3分面

image.png

雙分面
2.4幾何對象

image.png

image.png

image.png
當(dāng)全局變量和局部變量沖突時(shí),以局部變量為主?。。?/p>
ggplot(test,aes(x = Sepal.Length,
y = Petal.Length,
color = Species)) +"#color屬于全局變量"
geom_point()+
geom_smooth(color = "black")"#color屬于局部變量"

image.png
ggplot(test,aes(x = Sepal.Length,
y = Petal.Length,
color = Species)) +"#color為全局變量"
geom_point()+
geom_smooth()"#作為局部變量的color已經(jīng)刪除"

image.png
2.5幾何對象

image.png
View(diamonds)
table(diamonds$cut)
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))
ggplot(data = diamonds) +
stat_count(mapping = aes(x = cut))

image.png
ggplot(data = fre) + geom_bar(mapping = aes(x = Var1, y = Freq), stat = "identity")
image.png
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))
y=..prop..

image.png
2.6位置關(guān)系
(1)
2.7坐標(biāo)系

image.png

完成的繪圖模板
ggplot(data = x, mapping = aes(x = Sepal.Width, y = Species,
),
) +
geom_violin(aes(fill=Species))+
geom_boxplot() +
geom_jitter(aes(shape=Species))

image.png
3.ggpubr語法
4.圖片的保存和導(dǎo)出
4.1ggsave

image.png
4.2eoffice

image.png