You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R语言lattice包分面图中修改月份标签为数字显示

R lattice分面标题去除变量前缀的实现方法

lattice默认的分面标题会渲染为「分面变量名: 取值」的格式,要让分面仅显示月份数字,可通过以下两种方式实现:

方法1:预处理分面变量(修改原始数据集)

将数据集中的Month字段转换为因子,直接指定标签为月份数字,调用绘图函数时就不会显示变量前缀:

library("lattice")
airquality$Month <- factor(airquality$Month, levels = 5:9, labels = 5:9)
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality
)

方法2:自定义分面条(不修改原始数据集)

在xyplot参数中通过strip参数指定自定义显示文本,无需改动原数据:

library("lattice")
xyplot(Ozone ~ Temp | Month,
layout=c(1,5),
data=airquality,
strip = strip.custom(factor.levels = as.character(unique(airquality$Month)))
)

内容的提问来源于stack exchange,提问作者rrkk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 05:00:04