df1 <- data.frame(
key = c("A", "B", "B", "C", "D", "E"),
start = c(0, 1, 6, 5, 6, 9),
end = c(5, 4, 10, 9, 8, 11)
)
p <- ggplot(df1, aes(x = start, xend = end, color = key))
p +
geom_lexis()
p +
geom_lexis(gap_filler = FALSE)
p +
geom_lexis(aes(linetype = after_stat(type)),
point_show = FALSE
)
# change point appearance
p + geom_lexis(
point_colour = "black",
size = 3,
shape = 21,
fill = "white",
stroke = 1
)
# missing values will be removed
df2 <- data.frame(
key = c("A", "B", "B", "C", "D"),
start = c(0, 1, 7, 5, 6),
end = c(5, 4, 13, 9, NA)
)
ggplot(df2, aes(x = start, xend = end, color = key)) +
geom_lexis()
# Ideally, `x` values should be increasing, unlike
# in the next example
df3 <- data.frame(x = Sys.Date() - 0:2, xend = Sys.Date() + 1:3)
ggplot(df3, aes(x = x, xend = xend)) +
geom_lexis()
# If `x` is of class Date, `xend` can't be of class `POSIXt` or
# `POSIXct`. The error is thrown by the `scales::date_trans` function.
if (FALSE) {
ggplot(
data.frame(x = Sys.Date(), xend = Sys.time()),
aes(x = x, xend = xend)
) +
geom_lexis()
}
Run the code above in your browser using DataLab