今天我們學(xué)習一點簡單的,實現(xiàn)下面這張圖

圖片.png
繪圖:
1. 首先加載數(shù)據(jù),然后用查看一下數(shù)據(jù)長什么樣子
head(dat)
## tSNE_1 tSNE_2 cell cluster
## 6A-11 -1.910859 -26.09210 6A-11 2
## 6A-13 -3.498666 -27.66961 6A-13 2
## 6A-14 -7.646899 -12.26195 6A-14 2
## 6A-15 -2.986069 -27.00602 6A-15 2
## 6A-16 -7.633320 -12.21226 6A-16 2
## 6A-17 -4.207616 -25.12467 6A-17 2
2. 開始畫圖:
首先,可以看出這張圖是張點圖,而x軸、y軸和點的顏色分別對應(yīng)數(shù)據(jù)中的tSNE_1、tSNE_2和cluster,所以用映射來實現(xiàn)。
library(ggplot2)
ggplot(dat,mapping = aes(x=tSNE_1,
y=tSNE_2,
col=cluster))+
geom_point()
圖片
3. 給cluster添加一個圓圈在ggplot2中通過stat_ellipse()實現(xiàn)。
rm(list=ls())
load("for_tSNE.pos.Rdata")
ggplot(dat,mapping = aes(x=tSNE_1,
y=tSNE_2,
col=cluster))+
geom_point()+
stat_ellipse()
圖片
4. 修改圖片細節(jié):
* stat_ellipse()中增加參數(shù),按cluster畫填充
ggplot(dat,mapping = aes(x=tSNE_1,
y=tSNE_2,
col=cluster))+
geom_point()+
stat_ellipse(aes(fill=cluster),
geom = "polygon")

圖片.png
* 把填充的透明度改一改
ggplot(dat,mapping = aes(x=tSNE_1,
y=tSNE_2,
col=cluster))+
geom_point()+
stat_ellipse(aes(fill=cluster),
geom = "polygon",
alpha=1/5)
圖片
* 最后再對圖片進行一些微調(diào):點的大小、圓圈實線改虛線、圓圈線的粗細、坐標軸的出戲以及主題等等。
ggplot(dat,mapping = aes(x=tSNE_1,
y=tSNE_2,
col=cluster))+
geom_point(size=2)+
stat_ellipse(aes(fill=cluster),
geom = "polygon",
linetype = 2, ###圓圈線的類型
size=1, ###圓圈線的粗細
alpha=1/5)+
theme_classic()+
theme(axis.line = element_line(size=1.2, colour = "black")) ###坐標軸的粗細
圖片
對比一下:
圖片
基礎(chǔ)知識,多多學(xué)習