如何在R中使用莱迪思封装制作的直方图中更改x轴上的刻度?

时间:2011-09-10 17:08:13

标签: r histogram lattice

我已成功为我的数据集中的所有年份和月份制作可变风速的直方图。但是我想要以1英里/小时的间隔标记x轴。每个箱也是1英里/小时的间隔。目前默认情况下,x轴以20英里/小时的间隔标记。

这是我的R代码。

histogram(~ as.numeric(spd) | factor(month) + factor(year), data = spd_sub, 
  xlab = "spd in miles/hour", 
  nint= max(as.numeric(spd))-min(as.numeric(spd)), layout = c(1, 1))

知道怎么做吗?

1 个答案:

答案 0 :(得分:5)

也许这可能是一些值得思考的问题。请注意使用scales

library(lattice)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
xyplot(lat ~ long | Depth, data = quakes)

这将为您提供以下图表。 enter image description here

如果你设置了scale参数:

xyplot(lat ~ long | Depth, data = quakes,
        scales = list(y = list(at = seq(from = 0, to = -50, by = -10))))

enter image description here

免费提供直方图(更改刻度线并旋转它们):

histogram( ~ height | voice.part, data = singer,
    xlab = "Height (inches)", type = "density",
    panel = function(x, ...) {
        panel.histogram(x, ...)
        panel.mathdensity(dmath = dnorm, col = "black",
            args = list(mean=mean(x),sd=sd(x)))
    },
    scales = list(x = list(at = seq(60, 80, by = 2), rot = 45)))

enter image description here