如何在R lattice包中显示数字
How to show the number in R lattice package
我们使用 R 4.0.5,lattice 0.20-38,MacOS 10.14.5。
library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)
我们根据这段代码得到了下图。
我们要将每个图形的名称“Month”更改为月份数。合成(damy)图像如下所示。我们应该怎么做?
将 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 的标签,我们使用 match
和 unique
来获得它。
我们使用 R 4.0.5,lattice 0.20-38,MacOS 10.14.5。
library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)
我们根据这段代码得到了下图。
我们要将每个图形的名称“Month”更改为月份数。合成(damy)图像如下所示。我们应该怎么做?
将 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 的标签,我们使用 match
和 unique
来获得它。