I have the following test data frame in 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))
I would like to plot df using xyplot in 3 different panels, where the froups are defined by the type, and value is plotted against Date, where the bottom panel would not have any tick labels while the other two panels would. Here is the code that I used to plot it:
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)
)
However this code did not help. Do any of you know how to solve this issue? Many thanks in advance.
Does this do what you are looking for?
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)
)
This suppresses the ticks and labels in the first panel and manually sets them for the other 2.