美文网首页R
使用umap R包绘制UMAP图

使用umap R包绘制UMAP图

作者: zjl_8c97 | 来源:发表于2019-12-17 15:58 被阅读0次

    一、安装

    1、conda install -c conda-forge umap-learn

    2、进入R:

    devtools::install_github("ropenscilabs/umapr")

    library(umapr)

    提示:

    Warning message:

    Python not installed

    Please install anaconda or miniconda

    https://conda.io/projects/conda/en/latest/user-guide/install/index.html

    Warning message:

    umap-learn module is not installed

    Please run one of the following:

    conda install -n r-reticulate -c conda-forge umap-learn

    conda activate r-reticulate; pip install umap-learn

    解决:

    library(reticulate)

    py_available() #结果若为FALSE则说明未安装python或python路径不在R的搜索路径中。

    use_python("/root/miniconda2/envs/r-reticulate/bin/python", required = T)  #填写自己的python路径

    二、绘图

    library(reticulate)

    use_python("/root/miniconda2/envs/r-reticulate/bin/python", required = T)

    library(umapr)

    library(dplyr)

    library(magrittr)

    library(ggplot2)

    library(ggsci)

    df <- read.table("/.../smart_seq_scaled_t.csv",sep=",", head=T, row.names=1)

    df2 <- apply(df,1,as.numeric)

    day <- read.table("/../day_info",sep="\t",row.names=1,head=T)

    embedding <- umap(df2,n_neighbors=7L,min_dist =0.6,metric="braycurtis")

    p <- embedding %>%

      mutate(days =day$days) %>%

      ggplot(aes(UMAP1, UMAP2, color = days)) + geom_point() + ggtitle("neighbors7_min_dist0.6_braycurtis") + scale_color_lancet() + 

    theme(panel.grid=element_blank(),panel.background=element_rect(fill='transparent', color='black'),  plot.margin = unit(c(0.2, 0.2, 0.2, 0.2), "inches"), plot.title = element_text(hjust = 0.5, vjust =4,size=20,face = "bold"), legend.title = element_blank(), axis.text = element_text(colour = "black",face="plain",size=15), axis.title = element_text(colour = "black",face="plain",size=15), axis.line = element_line(colour = "black",size = 0.5), axis.ticks = element_line(colour= "black",size=0.5),legend.key = element_rect(fill='transparent', color='transparent'), legend.key.size = unit(0.2,"inches"), legend.text = element_text(colour = "black", face="plain", size=13))

    ggsave("/.../neighbors7_min_dist06_braycurtis.png",p)

    ggsave("/.../neighbors7_min_dist0.6_braycurtis.pdf",p)

    三、结果

    相关文章

      网友评论

        本文标题:使用umap R包绘制UMAP图

        本文链接:https://www.haomeiwen.com/subject/qkljiftx.html