如何在 UpsetR 图中使用自定义字体系列?

How to use custom font family in UpsetR plots?

我正在尝试使用 UpSetR package; however, I'd like to control the family of fonts. The ideal approach would be using theme function from ggplot2 but this is not supported at the moment by UpSetR (there's an open issue from 2016 on GitHub here) 创建集合图,结果为 NULL

创建测试图的示例:

# R version ---------------------------------------------------------------
# platform       x86_64-w64-mingw32          
# arch           x86_64                      
# os             mingw32                     
# system         x86_64, mingw32             
# status                                     
# major          3                           
# minor          5.1                         
# year           2018                        
# month          07                          
# day            02                          
# svn rev        74947                       
# language       R                           
# version.string R version 3.5.1 (2018-07-02)
# nickname       Feather Spray 

# Package versions --------------------------------------------------------
# Assumes packages are already installed
packageVersion(pkg = "extrafont") == "0.17"
packageVersion(pkg = "UpSetR") == "1.3.3"
packageVersion(pkg = "ggplot2") == "3.1.0"

# Load UpSetR -------------------------------------------------------------
library(UpSetR)
library(extrafont)
library(ggplot2)

# Example -----------------------------------------------------------------
movies <- read.csv( system.file("extdata", "movies.csv", package = "UpSetR"), header=T, sep=";" )

upset(data = movies, 
      order.by = "freq", 
      keep.order = TRUE,
      mainbar.y.label = "Example plot", 
      point.size = 4, 
      line.size = 1,
      sets.x.label = NULL)

展望未来,理想的情况是 UpSetR 支持来自 ggplot2 的层/+ theme() 功能;但是,UpSetR 无法使用“+”"layer name" 逻辑。例如,如果在上面的调用末尾添加 + theme(text = element_text(family = "Times New Roman")),它将 return NULL 并且不会产生任何情节。

能否请您提出任何解决方法(或包中函数的自定义)以支持 UpSetR 生成的上述示例图中的自定义字体?或者,有没有办法在所有绘图中强制使用默认字体系列而无需手动指定任何 family 参数?

使用 another UpSet implementation 实现此目的的一种方法是:

# install if needed
if(!require(ggplot2movies)) install.packages('ggplot2movies')
if(!require(devtools)) install.packages('devtools')
devtools::install_github('krassowski/complex-upset')

movies = as.data.frame(ggplot2movies::movies)
genres = c('Action', 'Animation', 'Comedy', 'Drama', 'Documentary', 'Romance', 'Short')

library(ComplexUpset)
library(ggplot2)

upset(
    movies, genres, min_size=45, width_ratio=0.1,
    themes=upset_default_themes(text=element_text(family='Times New Roman'))
)

免责声明:我是此实现的作者。