简体   繁体   English

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

[英]How to use custom font family in UpsetR plots?

I am trying to create set plot using the UpSetR package;我正在尝试使用UpSetR包创建集合图; 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 ) and results in NULL .理想的方法是使用来自ggplot2 theme函数,但目前 UpSetR 不支持此功能(此处在 GitHub 上有 2016 年的未解决问题)并导致NULL

Example to create test plot:创建测试图的示例:

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

Going forward, the ideal would be where UpSetR supports layers / + theme() function from ggplot2 ;展望未来,理想情况是 UpSetR 支持来自ggplot2 layer / + theme()函数; however, the UpSetR is not able to use "+" "layer name" logic.但是,UpSetR 不能使用“+”“层名称”逻辑。 For example, if + theme(text = element_text(family = "Times New Roman")) were added at the end of the call above, it would return NULL and produce no plot.例如,如果在上述调用的末尾添加+ theme(text = element_text(family = "Times New Roman")) ,它将返回NULL并且不产生任何情节。

Can you please suggest any workaround (or customization of function in package) that would support custom fonts in the example plot above produced by UpSetR?您能否建议任何支持 UpSetR 生成的上述示例图中的自定义字体的解决方法(或包中的函数自定义)? Alternatively, is there a way to force default font family in all plots without specifying any family arguments manually?或者,有没有办法在所有图中强制使用默认字体系列,而无需手动指定任何family参数?

One way of achieving this with another UpSet implementation would be:使用另一个 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'))
)

对 Times New Roman 不满

Disclamer: I am the author of this implementation.免责声明:我是这个实现的作者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM