首页 > 解决方案 > 如何使用cowplot创建图表而不激活空白窗口

问题描述

这是一个代表:

require(cowplot)

plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) + 
geom_point(size=2.5)

plot.diamonds <- ggplot(diamonds, aes(clarity, fill = cut)) + 
geom_bar()+theme(axis.text.x = element_text(angle=70, vjust=0.5))

testing <- plot_grid(plot.mpg, plot.diamonds, labels = c('A', 'B'))

当我运行上述行时,会打开一个空白窗口。我怎样才能禁用它?

我的 sessionInfo 是:

sessionInfo() R 版本 3.4.4 (2018-03-15) 平台:x86_64-pc-linux-gnu (64-bit) 运行于:Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
[1] LC_CTYPE=en_IN       LC_NUMERIC=C         LC_TIME=en_IN       
[4] LC_COLLATE=en_IN     LC_MONETARY=en_IN    LC_MESSAGES=en_IN   
[7] LC_PAPER=en_IN       LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cowplot_0.9.1 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.3-2 scales_0.5.0     compiler_3.4.4  
[5] lazyeval_0.2.1   plyr_1.8.4       gtable_0.2.0     tibble_1.3.4    
[9] Rcpp_0.12.15     grid_3.4.4       digest_0.6.13    rlang_0.2.0     
[13] munsell_0.4.3   

我从 CRAN 下载了 tar 球 - cowplot_0.9.2.tar.gz 并安装了它。我仍然有同样的问题:

我的 sessionInfo 是:

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
[1] LC_CTYPE=en_IN       LC_NUMERIC=C         LC_TIME=en_IN       
[4] LC_COLLATE=en_IN     LC_MONETARY=en_IN    LC_MESSAGES=en_IN   
[7] LC_PAPER=en_IN       LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cowplot_0.9.2      ggplot2_2.2.1.9000

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16      viridisLite_0.3.0 digest_0.6.15     withr_2.1.2      
[5] grid_3.4.4        plyr_1.8.4        gtable_0.2.0   scales_0.5.0.9000
[9] pillar_1.2.2      rlang_0.2.0.9001  lazyeval_0.2.1    labeling_0.3     
[13] munsell_0.4.3     compiler_3.4.4    colorspace_1.3-2  tibble_1.4.2     
> 

标签: rggplot2cowplot

解决方案


从您的会话信息中,我可以看到您正在运行 cowplot 版本 0.9.1。该版本存在特定情况下会弹出空白窗口的问题。如果您升级到 0.9.2(CRAN 上的当前版本),问题应该会消失。


推荐阅读