TSNE绘制及ggthemeassist的使用
# 加载包
library(Rtsne)
library(ggplot2)
library(ggpubr)
library(ggThemeAssist)#首先安装该包,之后再在Rstudio界面中点击addins
library(showtext)
showtext.auto()
show_point_shapes()
#Examples
# 使用示例数据
iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
set.seed(42)
tsne_out <- Rtsne(iris_matrix,pca=F,perplexity=30,theta=0.0) # Run TSNE
plot(tsne_out$Y,col=iris_unique$Species, asp=1)
colnames(data) <- c("TSNE1","TSNE2","species")
data <- data.frame(tsne_out$Y,iris_unique$Species)
下载和安装了ggThemeAssist包后就可以在这例看到
ggplot Theme Assistant,使用的时候需要先高亮选选择一段跑过的ggplot绘图代码
如这样所示
之后便会出现交互式窗口用来调整参数美化图片,设计主题等等。
#绘图模块
ggplot(data,aes(TSNE1,TSNE2,fill = species))+
geom_point(size=5.5,colour="black",alpha=0.4,shape=21)+
scale_fill_manual(values=c("#00AFBB","#E7B800","blue"))+
theme_pubr() + theme(axis.line = element_line(colour = NA),
panel.grid.major = element_line(colour = NA,
size = 1.3, linetype = "blank"),
axis.title = element_text(family = "serif",
size = 15, face = "bold"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(size = 15),
axis.text.y = element_text(size = 15),
legend.text = element_text(size = 12,
face = "bold", family = "Helvetica"),
legend.title = element_text(size = 13,
family = "mono"), panel.background = element_rect(fill = NA,
size = 1, linetype = "dashed"), plot.background = element_rect(colour = NA,
size = 2, linetype = "dotted"), legend.key = element_rect(fill = NA,
linetype = "blank"), legend.background = element_rect(fill = "white",
size = 0.8, linetype = "twodash"),
legend.position = c(20, 20)) + theme(plot.subtitle = element_text(family = 'Arial', size = 12, face = 'bold'), axis.line = element_line(colour = 'black', size = 1, linetype = 'solid')) +
labs(caption = 'TSNE_PLOT')+
theme(axis.ticks = element_line(colour = "black"),
panel.grid.major = element_line(linetype = "solid"),
panel.grid.minor = element_line(colour = NA,
size = 1.1), legend.position = c(0.15, 1), plot.margin = unit(c(2,2,2,2),"cm"))
能够满足一般的绘图需要了。
---------
以上