1

我正在尝试使用UpSetR包创建设置图;但是,我想控制字体系列。理想的方法是使用theme函数 fromggplot2但 UpSetR 目前不支持此功能(此处GitHub 上有一个 2016 年的未解决问题)并导致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 支持+ theme()来自的层/功能ggplot2;但是,UpSetR 不能使用“+”“层名”逻辑。例如,如果+ theme(text = element_text(family = "Times New Roman"))在上面的调用结束时添加,它将返回NULL并且不产生任何情节。

您能否在上面由 UpSetR 生成的示例图中建议任何支持自定义字体的解决方法(或包中的功能自定义)?或者,有没有办法在所有图中强制使用默认字体系列而不family手动指定任何参数?

4

1 回答 1

4

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

# 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'))
)

对时代新罗马感到不安

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

于 2020-03-13T00:50:47.723 回答