ggplot scale_continuous如何扩展参数工作? [英] How does ggplot scale_continuous expand argument work?

查看:206
本文介绍了ggplot scale_continuous如何扩展参数工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚 scale_continuous() 展开参数是如何工作的。根据 scale_continuous文档

< blockquote>

长度为2的数值向量给出乘法和加法的
扩展常量。这些常量确保将数据放置在距离轴一定距离处
。对于
连续变量,缺省值是c(0.05,0),对于离散变量,缺省值是c(0,0.6)。

因为它们是扩张常数,所以它们不是实际的单位。有什么方法可以将它们转换为实际测量值来预测实际输出吗?除了0以外的任何东西,我只是尝试随机数字,直到它工作。解决方案

该文件非常清晰。如果您手动设置 limits ,则会更清晰。我将举一些例子来说明它是如何工作的:



第一个参数使扩展等于其乘以限制范围;

  ggplot(mpg,aes(displ,hwy))+ 
geom_point()+
scale_x_continuous(limits = c(1,7),expand = c(0.5,0))
#最右边的位置将是7 +(7-1)* 0.5 = 10

第二个给出了轴两端的绝对扩展:

  ggplot(mpg, aes(displ,hwy))+ 
geom_point()+
scale_x_continuous(limits = c(1,7),expand = c(0.5,2))
#right right position will be 7 +(7-1)* 0.5 + 2 = 12

最后,轴的结尾。


I am trying to figure out how scale_continuous() expand argument works. According to scale_continuous documentation:

A numeric vector of length two giving multiplicative and additive expansion constants. These constants ensure that the data is placed some distance away from the axes. The defaults are c(0.05, 0) for continuous variables, and c(0, 0.6) for discrete variables.

Since they are "expansion constants", they are not actual units. Is there any way to convert them to some actual measurement to predict the actual output? For anything except 0, I just try random numbers until it works. There must be a more proper way to approach this.

解决方案

The document is pretty clear. If you set limits manually, it would be more clear. I'll give some examples to show how it works:

the first argument gives expansion equal to its multiplication by limit range;

ggplot(mpg, aes(displ, hwy)) +
    geom_point() +
    scale_x_continuous(limits = c(1, 7), expand = c(0.5, 0))
# right most position will be 7 + (7-1) * 0.5 = 10

the second gives the absolute expansion added to both end of the axis:

ggplot(mpg, aes(displ, hwy)) +
    geom_point() +
    scale_x_continuous(limits = c(1, 7), expand = c(0.5, 2))
# right most position will be 7 + (7-1) * 0.5  + 2 = 12

Finally, the same expansion applies to both end of the axis.

这篇关于ggplot scale_continuous如何扩展参数工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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