数据挖掘0308
2021-03-08 本文已影响0人
五官端正123
所有资料来源于生信技能树
1. 常用的可视化R包
![](https://img.haomeiwen.com/i25596489/5797e8542b620882.png)
(1)Base
![](https://img.haomeiwen.com/i25596489/ed83c0b3d1754113.png)
![](https://img.haomeiwen.com/i25596489/3d74211e0c42a8cb.png)
高级函数是出图,低级函数是添砖加瓦
2.ggplot2语法
![](https://img.haomeiwen.com/i25596489/aa300b950b9f42e1.png)
入门级模板
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
2.1属性设置
![](https://img.haomeiwen.com/i25596489/8da539f315f48022.png)
geom_point(mapping = aes(x = displ, y = hwy), color = "blue")
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy),
size = 5, # 点的大小5mm
alpha = 0.5, # 透明度 50%
shape = "※") # 点的形状
![](https://img.haomeiwen.com/i25596489/decfd876b6fa18e9.png)
2.2映射
![](https://img.haomeiwen.com/i25596489/d207eef2427b0ee0.png)
![](https://img.haomeiwen.com/i25596489/9e9632e86fce286b.png)
![](https://img.haomeiwen.com/i25596489/f5d487d8816ce427.png)
![](https://img.haomeiwen.com/i25596489/15023e82bd00e835.png)
![](https://img.haomeiwen.com/i25596489/c9537ee81dcefd94.png)
搜索16禁止颜色代码,替代下图中的红框
![](https://img.haomeiwen.com/i25596489/de486fb2602a0497.png)
![](https://img.haomeiwen.com/i25596489/1fc085016fc0a041.png)
![](https://img.haomeiwen.com/i25596489/2dbff281a897ab2d.png)
2.3分面
![](https://img.haomeiwen.com/i25596489/6cd8535ad66bb045.png)
![](https://img.haomeiwen.com/i25596489/45422f12056a46d5.png)
2.4几何对象
![](https://img.haomeiwen.com/i25596489/00ee9ac22d96db63.png)
![](https://img.haomeiwen.com/i25596489/09366de4b7233995.png)
![](https://img.haomeiwen.com/i25596489/90c130dc6af2fc5f.png)
当全局变量和局部变量冲突时,以局部变量为主!!!
ggplot(test,aes(x = Sepal.Length,
y = Petal.Length,
color = Species)) +"#color属于全局变量"
geom_point()+
geom_smooth(color = "black")"#color属于局部变量"
![](https://img.haomeiwen.com/i25596489/ac8fb2c5dfe2309f.png)
ggplot(test,aes(x = Sepal.Length,
y = Petal.Length,
color = Species)) +"#color为全局变量"
geom_point()+
geom_smooth()"#作为局部变量的color已经删除"
![](https://img.haomeiwen.com/i25596489/01f032c085911c29.png)
2.5几何对象
![](https://img.haomeiwen.com/i25596489/b42e61f8439442b9.png)
View(diamonds)
table(diamonds$cut)
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))
ggplot(data = diamonds) +
stat_count(mapping = aes(x = cut))
![](https://img.haomeiwen.com/i25596489/696a79f26acff385.png)
ggplot(data = fre) + geom_bar(mapping = aes(x = Var1, y = Freq), stat = "identity")
![](https://img.haomeiwen.com/i25596489/74cb6736ec47b5a0.png)
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))
y=..prop..
![](https://img.haomeiwen.com/i25596489/2b87d7b63c360f3b.png)
2.6位置关系
(1)
2.7坐标系
![](https://img.haomeiwen.com/i25596489/bcdef01f05b92856.png)
![](https://img.haomeiwen.com/i25596489/5e156dd730620b52.png)
ggplot(data = x, mapping = aes(x = Sepal.Width, y = Species,
),
) +
geom_violin(aes(fill=Species))+
geom_boxplot() +
geom_jitter(aes(shape=Species))
![](https://img.haomeiwen.com/i25596489/f974a6bc97e5ae4f.png)
3.ggpubr语法
4.图片的保存和导出
4.1ggsave
![](https://img.haomeiwen.com/i25596489/6004212db79f3294.png)
4.2eoffice
![](https://img.haomeiwen.com/i25596489/7b34b6b4e58d5aaf.png)