ggtern禁用ggplot2的某些主题 [英] ggtern disables some themes from ggplot2

查看:104
本文介绍了ggtern禁用ggplot2的某些主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将主题切换为theme_bw()无效,theme_grey()似乎已被确定优先级.有什么想法吗?

Trying to switch the theme to theme_bw() is not working, theme_grey() seems to be prioritized. Any ideas why?

ggplot(data=mpg,aes(y=year,x=cyl)) + geom_point() + theme_bw()

编辑:

如注释中所建议,在干净的R会话中运行时,此方法有效.但是,当我在加载了ggtern的会话中实现代码时,就会出现问题.

As suggested in the comments, this works when run in a clean R session. But when I implement the code in a session with ggtern loaded, the problem crops up.

library(ggplot2)
#Warning message:
#package ‘ggplot2’ was built under R version 3.2.5 
ggplot(data=mpg,aes(y=year,x=cyl)) + geom_point() + theme_bw()

# sessionInfo()
# R version 3.2.2 (2015-08-14)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 8 x64 (build 9200)
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
# [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
# [5] LC_TIME=English_United States.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] ggplot2_2.1.0
# 
# loaded via a namespace (and not attached):
#   [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     plyr_1.8.3       tools_3.2.2      gtable_0.1.2    
# [7] Rcpp_0.12.2      grid_3.2.2       munsell_0.4.2 

library(ggtern)
#Loading required package: ggplot2

#Attaching package: ‘ggtern’

#The following objects are masked from ‘package:ggplot2’:

    #aes, calc_element, ggplot, ggplot_build, ggplot_gtable, ggplotGrob, ggsave, is.ggplot, layer_data,
    #layer_grob, layer_scales, theme, theme_bw, theme_classic, theme_dark, theme_get, theme_gray,
    #theme_light, theme_linedraw, theme_minimal, theme_set, theme_void

#Warning messages:
#1: package ‘ggtern’ was built under R version 3.2.5 
#2: package ‘ggplot2’ was built under R version 3.2.5 
ggplot(data=mpg,aes(y=year,x=cyl)) + geom_point() + theme_bw()

# sessionInfo()
# R version 3.2.2 (2015-08-14)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 8 x64 (build 9200)
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
# [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
# [5] LC_TIME=English_United States.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] ggtern_2.1.1  ggplot2_2.1.0
# 
# loaded via a namespace (and not attached):
#   [1] Rcpp_0.12.2         lattice_0.20-33     MASS_7.3-45         grid_3.2.2          plyr_1.8.3         
# [6] bayesm_3.0-2        gtable_0.1.2        magrittr_1.5        scales_0.4.0        stringi_1.0-1      
# [11] compositions_1.40-1 robustbase_0.92-5   latex2exp_0.4.0     boot_1.3-17         labeling_0.3       
# [16] proto_0.3-10        tools_3.2.2         stringr_1.0.0       energy_1.6.2        DEoptimR_1.0-4     
# [21] munsell_0.4.2       colorspace_1.2-6    tensorA_0.36        gridExtra_2.0.0    

就像ggtern一样,它们掩盖了ggplot2的许多主题.

Looks like ggtern masks a lot of the themes from ggplot2.

推荐答案

ggtern屏蔽了ggplot2中的每个默认主题,这是因为在编写此软件时,大约有60个新主题元素具有已创建,为了使ggtern正确呈现而存在.有关新主题元素的完整列表,请运行以下命令:

ggtern masks EVERY default theme from ggplot2, and this is because when writing this software, some ~60 new theme elements have been created, which exist in order to make ggtern render correctly. For a comprehensive list of the new theme elements, run the following command:

library(ggtern)
?theme_elements

如上所述,由于ggtern还修改了一些基本主题元素,因此我意识到了一些冲突,并且自2.1.2 - 2.1.3版本以来,我已经完全修改了主题因此ggtern不再修改任何基本元素-希望这种烦人的行为现在已经消失了!

Having said the above, I was aware of some clashes, as you have identified, due to ggtern also modifying some of the base theme elements, and since about version 2.1.2 - 2.1.3, I have completely re-worked the themes so that ggtern no longer modifies any of the base elements -- hopefully this annoying behaviour has now gone away for good!

我正在制作关于包装的出版物,并且已经在完善许多长期的烦恼,因此,请从我的(

I am in the process of producing a publication on the package, and have been refining many many many long-tern annoyances, so please download and install the most recent version (2.1.4) from my (Bitbucket Repository). Embarrassingly, even the last 2.1.3 version on CRAN, I picked up on a pretty significant bug when running two plots in a grid.arrange type situation. This is an issue with the clipping mask, and something which has been resolved in 2.1.4 yet sent to CRAN, something I plan to do imminently.

无论如何,要回答您的问题,请升级您的版本,您正在运行版本2.1.0,该版本是ggplot2中的巨大修订之后不久发布的版本-实际上,不久之前,以前的版本是如此严重的问题,几乎需要重写ggtern的全部内容,因此,拥有完美的主题是我的首要任务.在最新版本中,由于我有时间细化和确定问题,因此应该解决了此问题-通过运行以下两(2)条命令(按此顺序,从干净的会话开始)进行了演示,除标题上明显的不同应该产生相同的结果:

Anyway, to answer your question, please upgrade your version, you are running version 2.1.0, which was a version released not long after a HUGE revision in ggplot2 -- in fact, not long earlier, prior versions were so heavily broken, requiring almost the entire re-writing of ggtern, so having perfect themes was the least of my priorities. In recent versions, since I have had time to refine and identify issues, this behaviour should have been resolved -- demonstrated by the following two (2) commands run (in this order, from a clean session), which, with the exception of the obvious difference in the titles, should yield identical results:

library(ggplot2)
ggplot(data=mpg,aes(y=year,x=cyl)) + 
    geom_point() + theme_bw() + 
    labs(title='From ggplot2')

library(ggtern)
ggplot(data=mpg,aes(y=year,x=cyl)) + 
    geom_point() + theme_bw() + 
    labs(title='From ggtern')

如果我能说的话,这似乎有点题外话,但实际上,整个问题实际上是源于与一件事之间的几个不同程度. ggplot2的设计没有裁剪蒙版,它使用了网格视口作为伪裁剪蒙版,因为它的所有图(极坐标变换除外)都绘制在矩形区域上.位于矩形区域之外的数据映射随后将被视口丢弃.另一方面,ggtern需要一个,因为它需要在矩形视口中容纳的三角形形状的多边形区域中进行渲染-众所周知, 三角形不适合方孔" 或俗话说!当减小轴限制时,数据映射可以并且经常确实位于三角形区域之外,并且这些数据映射需要删除或屏蔽(或在用户希望的情况下显示).删除不是一种选择,因为它会影响某些图形,例如多边形,路径,密度或轮廓图(我认为可能只有点几何是唯一不会受到潜在影响的图形),这仅留下一个选项-裁剪蒙版的实现.在某些早期版本中,未实现剪贴蒙版(有利于对数据进行子集设置),因此需要修改基本主题元素.如果有的话,也许是最初的差劲的设计",在许多代之后流传到令人沮丧的行为.

If I can just say, this may seem a little off-topic, but this whole problem actually originally stemmed, by a couple of degrees of separation, from one thing. ggplot2 was designed without clipping masks, it uses the grid viewport as essentially a pseudo clipping mask, because all of its plots (with the exception of the polar transformation), are rendered on a rectangular region. Data mappings that lie outside of the rectangular region are subsequently discarded by the viewport. ggtern on the other hand needs one, because it needs to render within a triangular shaped polygon region housed within a rectangular viewport -- and as everyone knows, 'triangles don't fit in square holes' or however the saying goes! When the axis limits are reduced, data mappings can, and often do, lie outside of the triangular region, and these need to be either deleted or masked (or shown if the user so wishes). Deleting is not an option, since it would then affect certain plots like polygon, path, density or contour plots (I think probably point geometries are the only ones which are not potentially affected), which leaves only one option -- implementation of clipping mask. In some of the earlier versions, a clipping mask wasn't implemented (in favour of subsetting the data) thus requiring modifications of base theme elements. If anything, perhaps an initial 'poor design', has flowed on many generations later to a frustrating behaviour.

这篇关于ggtern禁用ggplot2的某些主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆