Closed
Description
---- Feature Request: Natively Cap the Axis Lines ----
It would be amazing to have the option to cap the axis lines, such as featured on the lemon
package. The lemon
package, however, requires to remove the ggplot2 default axis lines so that new ones can be drawn:
In order to manipulate the axis lines, they must be drawn. Modify the theme so the panel.border is not drawn (it will be on top of the axis lines), and have the axis lines drawn.
Therefore, it would be nice being able to cap the axis lines natively (without getting rid of the original axis lines).
Please find below a reprex of an example chart with capped axis lines:
# one can install the `lemon` package from CRAN.
# install.packages('lemon')
library(tidyverse)
library(lemon)
set.seed(2)
letters_data <- purrr::map_dfr(
letters,
~ data.frame(
idx = 1:400,
value = cumsum(runif(400, -1, 1)),
type = .,
flag = sample(c(TRUE, FALSE), size = 400, replace = TRUE),
stringsAsFactors = FALSE
)
)
letters_data %>%
ggplot() +
geom_line(aes(idx, value, colour = type)) +
coord_capped_cart(bottom = "both",
left = "both",
ylim = c(-50,25)) +
theme_classic() +
theme(legend.position="none",
axis.ticks.length = unit(.25, "cm"),
axis.line = element_line()) +
coord_capped_cart(bottom=capped_horizontal(),
xlim = c(0, 400),
ylim = c(-40, 20),
left=capped_vertical(capped = "both"))