首页 > 解决方案 > 如何在 R lattice 包中显示数字

问题描述

我们使用 R 4.0.5,lattice 0.20-38,MacOS 10.14.5。

library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)

我们根据这段代码得到了下图。 在此处输入图像描述

我们想将每个数字“月”的名称更改为月数。合成(损坏)图像如下所示。我们应该怎么做?

在此处输入图像描述

标签: rlattice

解决方案


将列更改month为因子。

library(lattice)

lattice::xyplot(Ozone ~ Temp | Month,
       layout=c(1,5),
       data = transform(airquality, Month = factor(match(Month, unique(Month))))
)

在此处输入图像描述

请注意,数据Month值是从 5 到 9,但由于您想要从 1 到 5 的标签,我们使用matchunique得到它。


推荐阅读