zoukankan      html  css  js  c++  java
  • ggplot常见语法汇总查询

    主图

    散点图

    柱状图

    折线图

    小提琴图

    点图

    进化树

    圈图

    Alluvial图

    Sankey Diagram

    plot(getSankey(colData(muraro)$cell_type1,  muraro_to_seger$scmap_cluster_labs[,1], plot_height=400))
    
    library(RColorBrewer)
    library(scmap)
    print(load("-/project/singleCell/mouse/Integration/comp.df.Rdata"))
    comp.df$New_cluster <- factor(comp.df$New_cluster, levels = 1:13)
    unique(comp.df$New_cluster)
    
    plot(getSankey(comp.df$Old_cluster, comp.df$New_cluster, 
                   plot_width=400, plot_height=600, colors=brewer.pal(12,"Set1")))

    Marginal plot

    library(ggExtra)
    #  [density, histogram, boxplot, violin].
    ggMarginal(pcag, data=pca_HSCR2, groupColour = T, groupFill=T, size=4, type="boxplot")
    

    Heatmap

    坐标轴

    去掉不必要的到坐标轴的距离,使图形更加紧凑

    ggplot2 Bar Graph remove unnecessary distance between axis label and 0 count on y axis

    scale_y_discrete(expand = c(0,0))  

    在对应的坐标轴里用expand来控制

    坐标轴以百分比显示

    scale_y_continuous(labels = percent_format())
    

    x和y轴对角线翻转

    coord_flip()
    

      

    图例

    图例的顺序翻转

    scale_fill_manual(guide = guide_legend(reverse=F))
    

      

    分面

    添加直线

    geom_hline(yintercept=0, linetype="dashed", color = "gray30", size=0.1) +
    geom_vline(xintercept=6, color = "gray30", size=0.1) +

    主题

    theme_Publication <- function(base_size=11, base_family="helvetica") {
          library(grid)
          library(ggthemes)
          (theme_foundation(base_size=base_size, base_family=base_family)
           + theme(plot.title = element_text(face = "bold",
                                             size = rel(1.2), hjust = 0.5),
                   text = element_text(),
                   panel.background = element_rect(colour = NA),
                   plot.background = element_rect(colour = NA),
                   panel.border = element_rect(colour = NA),
                   axis.title = element_text(face = "bold",size = rel(1)),
                   axis.title.y = element_text(angle=90,vjust =2),
                   axis.title.x = element_text(vjust = -0.2),
                   axis.text = element_text(), 
                   axis.line = element_line(colour="black"),
                   axis.ticks = element_line(),
                   panel.grid.major = element_line(colour="#f0f0f0"),
                   panel.grid.minor = element_blank(),
                   legend.key = element_rect(colour = NA),
                   legend.position = "bottom",
                   legend.direction = "horizontal",
                   legend.key.size= unit(0.2, "cm"),
                   legend.margin = unit(0, "cm"),
                   legend.title = element_text(face="italic"),
                   # plot.margin=unit(c(10,5,5,5),"mm"),
                   plot.margin=unit(c(5,2,2,2),"mm"),
                   strip.background=element_rect(colour="#f0f0f0",fill="#f0f0f0"),
                   strip.text = element_text(face="bold")
              ))
          
    }
    
    scale_fill_Publication <- function(...){
          library(scales)
          discrete_scale("fill","Publication",manual_pal(values = c("#386cb0","#fdb462","#7fc97f","#ef3b2c","#662506","#a6cee3","#fb9a99","#984ea3","#ffff33")), ...)
    
    }
    
    scale_colour_Publication <- function(...){
          library(scales)
          discrete_scale("colour","Publication",manual_pal(values = c("#386cb0","#fdb462","#7fc97f","#ef3b2c","#662506","#a6cee3","#fb9a99","#984ea3","#ffff33")), ...)
    
    }
    

      

    持续添加~  

  • 相关阅读:
    Boolean()类型转换
    ECMAscript 变量作用域
    jQuery 添加样式属性的优先级别
    css类选择器类名覆盖优先级
    巡风扫描器安装-windows部署
    atom无法安装插件的解决方法之一
    网络爬虫url跳转代码
    查看天气的代码
    三级地名菜单
    购物清单代码
  • 原文地址:https://www.cnblogs.com/leezx/p/11234380.html
Copyright © 2011-2022 走看看