【问题标题】:How to change the scales on the x axis in the Histogram made using Lattice package in R?如何更改使用 R 中的 Lattice 包制作的直方图中 x 轴上的比例?
【发布时间】:2011-09-10 17:08:13
【问题描述】:

我已经成功地为我的数据集中所有年份和月份的可变风速制作了直方图。但我希望 x 轴以 1 英里/小时的间隔标记。每个箱也是 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))

知道怎么做吗?

【问题讨论】:

标签: r histogram lattice


【解决方案1】:

也许这没什么好考虑的。注意scales的使用。

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

这为您提供了以下图表。

如果你设置 scales 参数:

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

一个免费的直方图(更改刻度线并旋转它们):

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)))

【讨论】:

  • 让我说得更具体一些。我有 10 年来以英里/小时为单位的每日风速数据,我希望为所有年份的每个月制作风速直方图,其中 x 轴以每小时 1 英里的间隔标记。我不能使用 seq 函数,因为我事先不知道所有直方图中的 bin 数量。
  • 我很确定你可以拥有比你需要的更多的东西,所以seq(-1000,1000,by=1) 只会标记那些落在情节上的人。也就是说,找出你需要在任一侧走的最远距离,并将其用于所有地块。
  • 非常感谢。它确实有效,但我的 x 轴刻度似乎有点不合适。我想在这里展示我的 pdf 格式或在 Quartz 中打开的图表,但目前我不知道该怎么做。谁能告诉我如何在这里得到我的 R 图,这样我的问题就很清楚了吗?
  • @Ridhima,见?jpeg 或说?png
猜你喜欢
  • 1970-01-01
  • 2017-09-11
  • 2020-07-05
  • 2014-08-07
  • 1970-01-01
  • 2020-08-27
  • 2018-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多