如何删除格子R中一个面板的轴标签
How to remove the label of axis of one panel in lattice R
我在 R 中有以下测试数据框:
library(lattice)
library(lubridate)
dates <- seq(today()-20, today(), by = 'days')
df <- rbind(data.frame(Date=dates, type = 'First', value = 1),
data.frame(Date=dates, type = 'Second', value = 2),
data.frame(Date=dates, type = 'Third', value = 3))
我想在 3 个不同的面板中使用 xyplot 绘制 df,其中组由 定义type 和 value 是根据 Date 绘制的,其中底部面板没有任何刻度标签,而其他两个面板会有.这是我用来绘制它的代码:
xyplot(value ~ Date | type, data = df, type = c("l", "g"),
scales = list(x = list(cex = 1),
y = list(relation = "free")),
panel = function(x, y, ..., subscripts) {
if (panel.number() == 1) {
panel.axis(at = c(-0.1, 0.0, 0.1, 0.2, 0.3, 0.4), labels = FALSE, draw.labels = FALSE, ticks = FALSE)
panel.xyplot(x, y, type = 'l', lwd = 2)
scales = list(y = list(labels = ""))
} else {
panel.xyplot(x, y, type = 'l', lwd = 2)
}
},
layout = c(1, 3),
abline=list(h=0, lty = 5)
)
但是这段代码没有帮助。你们有人知道如何解决这个问题吗?
非常感谢。
这是否符合您的要求?
xyplot(value ~ Date | type, data = df, type = c("l", "g"),
scales = list(x = list(cex = 1),
y = list(relation = "free",at=list("",seq(0,10,.2),seq(0,10,.2)))),
layout = c(1, 3),
abline=list(h=0, lty = 5)
)
这会抑制第一个面板中的刻度和标签,并为其他 2 个面板手动设置它们。
我在 R 中有以下测试数据框:
library(lattice)
library(lubridate)
dates <- seq(today()-20, today(), by = 'days')
df <- rbind(data.frame(Date=dates, type = 'First', value = 1),
data.frame(Date=dates, type = 'Second', value = 2),
data.frame(Date=dates, type = 'Third', value = 3))
我想在 3 个不同的面板中使用 xyplot 绘制 df,其中组由 定义type 和 value 是根据 Date 绘制的,其中底部面板没有任何刻度标签,而其他两个面板会有.这是我用来绘制它的代码:
xyplot(value ~ Date | type, data = df, type = c("l", "g"),
scales = list(x = list(cex = 1),
y = list(relation = "free")),
panel = function(x, y, ..., subscripts) {
if (panel.number() == 1) {
panel.axis(at = c(-0.1, 0.0, 0.1, 0.2, 0.3, 0.4), labels = FALSE, draw.labels = FALSE, ticks = FALSE)
panel.xyplot(x, y, type = 'l', lwd = 2)
scales = list(y = list(labels = ""))
} else {
panel.xyplot(x, y, type = 'l', lwd = 2)
}
},
layout = c(1, 3),
abline=list(h=0, lty = 5)
)
但是这段代码没有帮助。你们有人知道如何解决这个问题吗? 非常感谢。
这是否符合您的要求?
xyplot(value ~ Date | type, data = df, type = c("l", "g"),
scales = list(x = list(cex = 1),
y = list(relation = "free",at=list("",seq(0,10,.2),seq(0,10,.2)))),
layout = c(1, 3),
abline=list(h=0, lty = 5)
)
这会抑制第一个面板中的刻度和标签,并为其他 2 个面板手动设置它们。