TSNE绘制及ggthemeassist的使用

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"))

能够满足一般的绘图需要了。
在这里插入图片描述
---------
以上

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值