3

我想在双对数图中绘制 beta 分布。

x <- seq(0, 1, length=1001)
y <- dbeta(x, 0.1, 0.1)
plot(x, y, type="h", log="xy")

xtics 设置为

0.001
0.005
0.01 (without label)
0.05
0.1 (without label)
0.5
1 (without label)

我如何确定:

  1. 为主要小数位 (1.0, 0.1, 0.01, 0.001, 0.0001,...)

  2. 应该在小数位之间的 9 个位置绘制 tic(对于 0.01 和 0.1 之间的区域,它将是 0.01、0.02、0.03,......)

  3. 最大 y 范围应为 0.5

谢谢你的帮助。

斯文

4

2 回答 2

2

axes = FALSE为了对轴进行精细控制,请分别绘制它们,因此首先通过在调用中使用参数来抑制轴plot()

plot(x, y, type="h", log="xy", axes = FALSE)

然后根据需要添加轴

axis(side = 1, at = (locs <- 1/c(1,10,100,1000)), labels = locs)
axis(side = 2)
box()

问题 2 可以用同样的方式回答,您只需要指定刻度线的位置,也许将调用tcl中的参数参数设置axis()为比默认值小一点(即-0.5)。棘手的一点是生成您想要的次要刻度。我只能想出这个:

foo <- function(i, x, by) seq(x[i,1], x[i, 2], by = by[i])
locs2 <- unlist(lapply(seq_along(locs[-1]), FUN = foo, 
                       x= embed(locs, 2), by = abs(diff(locs)) / 9))

或者

locs2 <- c(outer(1:10, c(10, 100, 1000), "/"))

两者都给出:

R> locs2
 [1] 0.100 0.200 0.300 0.400 0.500 0.600 0.700 0.800 0.900 1.000 0.010 0.020
[13] 0.030 0.040 0.050 0.060 0.070 0.080 0.090 0.100 0.001 0.002 0.003 0.004
[25] 0.005 0.006 0.007 0.008 0.009 0.010

我们通过另一个调用来使用它们axis()

axis(side = 1, at = locs2, labels = NA, tcl = -0.2)

我们在这里使用 抑制标签labels = NA。您只需要弄清楚如何为at...

将这两个步骤放在一起,我们有:

plot(x, y, type="h", log="xy", axes = FALSE)
axis(side = 1, at = (locs <- 1/c(1,10,100,1000)), labels = locs)
axis(side = 1, at = locs2, labels = NA, tcl = -0.3)
axis(side = 2)
box()

产生:

轴调用产生的图

至于问题3,最大范围是什么意思?ylim您可以使用 的参数设置 y 轴上的限制plot()。您像这样提供限制(最小值和最大值)

plot(x, y, type="h", log="xy", axes = FALSE, ylim = c(0.2, 1))
axis(side = 1, at = (locs <- 1/c(1,10,100,1000)), labels = locs)
axis(side = 2)
box()

但是一个范围本身不足以定义限制,您需要告诉我们要在绘图上显示的最小值或最大值之一或您想要的实际值范围。

于 2011-06-07T17:48:55.757 回答
1

试试这个:

library(sfsmisc)

x <- seq(0, 1, length=1001)
y <- dbeta(x, 0.1, 0.1)
plot(x, y, type="h", log="xy", xaxt="n", yaxt="n", ylim=c(0.01, 0.5), main="Title")

atx <- c(0.0001, 0.001, 0.01, 0.1, 1, 10, 100)
eaxis(1, at=atx, labels=format(atx, drop0trailing=TRUE, scientific=FALSE), drop.1=FALSE, small.mult=10 )
aty <- c(0.01, 0.1, 0.5, 1, 10, 100)
eaxis(2, at=aty, labels=format(aty, drop0trailing=TRUE, scientific=FALSE), drop.1=FALSE, small.mult=10 )
grid()

在此处输入图像描述

于 2011-06-07T17:59:36.587 回答