美文网首页R语言
2020-04-07 复合韦恩图包(ComplexUpset)

2020-04-07 复合韦恩图包(ComplexUpset)

作者: iColors | 来源:发表于2020-04-14 10:08 被阅读0次

    此包兼有UpSetR的优点和ggplot2的可扩展性
    链接:https://github.com/krassowski/complex-upset

    1.先安装和加载包

    library(devtools)
    install_github("krassowski/complex-upset")
    library(ComplexUpset)
    library(tidyverse)
    if(!require(ggplot2movies)) install.packages('ggplot2movies')
    install.packages("ggbeeswarm")
    library(ggbeeswarm)
    

    2.准备数据和作图

    movies = as.data.frame(ggplot2movies::movies)
    genres = colnames(movies)[18:24]
    movies[genres] = movies[genres] == 1
    t(head(movies[genres], 3))
    movies[movies$mpaa == '', 'mpaa'] = NA
    movies = na.omit(movies)
    
    set_size(8, 8)
    
    set.seed(0)   # keep the same jitter for identical plots
    
    upset(
        movies,
        genres,
        annotations = list(
            'Length'=list(
                aes=aes(x=intersection, y=length),
                geom=geom_boxplot()
            ),
            'Rating'=list(
                aes=aes(x=intersection, y=rating),
                geom=list(
                    # checkout ggbeeswarm::geom_quasirandom for better results!
                    geom_jitter(aes(color=log10(votes))),
                    geom_violin(width=1.1, alpha=0.5)
                )
            ),
            'Budget'=list(
                aes=aes(x=intersection, y=budget),
                geom=geom_boxplot()
            )
        ),
        min_size=10,
        width_ratio=0.1
    )
    
    image.png
    set_size(8, 5)
    
    upset(
        movies,
        genres,
        annotations = list(
            'MPAA Raiting'=list(
                aes=aes(x=intersection, fill=mpaa),
                geom=list(
                    geom_bar(stat='count', position='fill'),
                    scale_y_continuous(labels=scales::percent_format()),
                    scale_fill_manual(values=c(
                        'R'='#E41A1C', 'PG'='#377EB8',
                        'PG-13'='#4DAF4A', 'NC-17'='#FF7F00'
                    ))
                )
            )
        ),
        width_ratio=0.1
    )
    
    image.png

    相关文章

      网友评论

        本文标题:2020-04-07 复合韦恩图包(ComplexUpset)

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