设置几何图形和缩放 ggplot2 的默认值 [英] Setting Defaults for geoms and scales ggplot2

查看:34
本文介绍了设置几何图形和缩放 ggplot2 的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ggplot2 的主题化可以很容易地降低对多个或重复的 + opt()... 行的需求.但是,我想知道是否有办法定义几何图形和缩放颜色的默认值.不必为每个图编写 ...+ scale_fill_manual() ,我希望能够设置它并忘记它.同样,我希望能够设置几何选项,这样我就不必重新输入(或忘记重新输入)诸如 geom_text(...,size=3,color="white")

Theming for ggplot2 makes it quite easy to relegate the need for multiple or repetitive + opt()... lines. However, I would like to know if there is a way to define defaults for geoms and scale colors. Instead of having to write ...+ scale_fill_manual() for each plot, I'd like to be able to set it and forget it. Similarly, I'd like to be able to set geom options so I don't have to retype (or forget to retype) things like geom_text(...,size=3,color="white")

更新:

对于音阶,似乎在某个时候有一种方法:

For scales, it seems at some point that there was a method:

set_default_scale("颜色", "离散", "灰色")

但是在最新版本的 ggplot2 中似乎没有这个功能.

But this function doesn't seem to exist in the most recent version of ggplot2.

推荐答案

现在有另一种方法.您基本上可以覆盖任何美学比例,例如:

There is another method for this now. You can essentially overwrite any aesthetics scale, for example:

scale_colour_discrete <- function(...) scale_colour_brewer(..., palette="Set2")
scale_fill_discrete <- function(...) scale_fill_brewer(... , palette="Set2")

现在,您的审美将随着该行为而着色或填充.'

Now, your aesthetics will be coloured or filled following that behaviour.'

根据:https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/w0Tl0T_U9dI

关于geoms的默认值,你可以使用update_geom_defaults,例如:

With respect to defaults to geoms, you can use update_geom_defaults, for example:

update_geom_defaults("line",   list(size = 2))

这篇关于设置几何图形和缩放 ggplot2 的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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