楼主: peijianshi
20577 4

[问答] R中pretty命令时干嘛用的? [推广有奖]

  • 0关注
  • 16粉丝

已卖:352份资源

副教授

80%

还不是VIP/贵宾

-

威望
0
论坛币
638 个
通用积分
2.3662
学术水平
12 点
热心指数
12 点
信用等级
5 点
经验
15373 点
帖子
636
精华
0
在线时间
568 小时
注册时间
2010-3-11
最后登录
2022-9-8

楼主
peijianshi 发表于 2015-11-5 17:22:45 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
R中pretty命令时干嘛用的?
谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:pretty RET pretty

R万岁!

沙发
hongweigg 发表于 2015-11-5 17:55:02
寻找答案:
?pretty

供参考:
pretty(x, n)  创建美观的分割点。通过选取n+1个等间距的取整值,将一个连续型变量x分割为n个区间。绘图中常用。

pretty {base}        R Documentation
Pretty Breakpoints
Description

Compute a sequence of about n+1 equally spaced ‘round’ values which cover the range of the values in x. The values are chosen so that they are 1, 2 or 5 times a power of 10.
Usage

pretty(x, ...)

## Default S3 method:
pretty(x, n = 5, min.n = n %/% 3,  shrink.sml = 0.75,
       high.u.bias = 1.5, u5.bias = .5 + 1.5*high.u.bias,
       eps.correct = 0, ...)

Arguments
x         

an object coercible to numeric by as.numeric.
n         

integer giving the desired number of intervals. Non-integer values are rounded down.
min.n         

nonnegative integer giving the minimal number of intervals. If min.n == 0, pretty(.) may return a single value.
shrink.sml         

positive numeric by a which a default scale is shrunk in the case when range(x) is very small (usually 0).
high.u.bias         

non-negative numeric, typically > 1. The interval unit is determined as {1,2,5,10} times b, a power of 10. Larger high.u.bias values favor larger units.
u5.bias         

non-negative numeric multiplier favoring factor 5 over 2. Default and ‘optimal’: u5.bias = .5 + 1.5*high.u.bias.
eps.correct         

integer code, one of {0,1,2}. If non-0, an epsilon correction is made at the boundaries such that the result boundaries will be outside range(x); in the small case, the correction is only done if eps.correct >= 2.
...         

further arguments for methods.
Details

pretty ignores non-finite values in x.

Let d <- max(x) - min(x) ≥ 0. If d is not (very close) to 0, we let c <- d/n, otherwise more or less c <- max(abs(range(x)))*shrink.sml / min.n. Then, the 10 base b is 10^(floor(log10(c))) such that b ≤ c < 10b.

Now determine the basic unit u as one of {1,2,5,10} b, depending on c/b in [1,10 and the two ‘bias’ coefficients, h =high.u.bias and f =u5.bias.

.........
References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
See Also

axTicks for the computation of pretty axis tick locations in plots, particularly on the log scale.
Examples

pretty(1:15)          # 0  2  4  6  8 10 12 14 16
pretty(1:15, h = 2)   # 0  5 10 15
pretty(1:15, n = 4)   # 0  5 10 15
pretty(1:15 * 2)      # 0  5 10 15 20 25 30
pretty(1:20)          # 0  5 10 15 20
pretty(1:20, n = 2)   # 0 10 20
pretty(1:20, n = 10)  # 0  2  4 ... 20

for(k in 5:11) {
  cat("k=", k, ": "); print(diff(range(pretty(100 + c(0, pi*10^-k)))))}

##-- more bizarre, when  min(x) == max(x):
pretty(pi)

add.names <- function(v) { names(v) <- paste(v); v}
utils::str(lapply(add.names(-10:20), pretty))
utils::str(lapply(add.names(0:20),   pretty, min.n = 0))
sapply(    add.names(0:20),   pretty, min.n = 4)

pretty(1.234e100)
pretty(1001.1001)
pretty(1001.1001, shrink = 0.2)
for(k in -7:3)
  cat("shrink=", formatC(2^k, width = 9),":",
      formatC(pretty(1001.1001, shrink.sml = 2^k), width = 6),"\n")

藤椅
yin479816697 发表于 2016-9-20 16:33:31
创建美观的分割点。通过选取n+1个等间距的取整值,将一个连续型变量x分割为n个 区间。绘图中常用

板凳
yin479816697 发表于 2016-9-20 16:33:53
创建美观的分割点。通过选取n+1个等间距的取整值,将一个连续型变量x分割为n个 区间。绘图中常用

报纸
zhangok 发表于 2016-10-6 02:52:46
yin479816697 发表于 2016-9-20 16:33
创建美观的分割点。通过选取n+1个等间距的取整值,将一个连续型变量x分割为n个 区间。绘图中常用
好详细,谢谢!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 06:33