我正在尝试在ggplot2中创建一个折线图,该折线图具有跨越轴的刻度线,而不是仅在轴的内部或外部。
我当前的代码是:
library(ggplot2)
data("economics", package = "ggplot2")
ggplot(economics, aes(x = date, y = uempmed)) +
geom_line() +
scale_x_date(breaks = seq.Date(from = as.Date("1968-12-31"), to = as.Date("1978-12-31"), by = "12 months"),
limits = as.Date(c("1968-01-01", "1978-12-31")), labels = scales::date_format("%y")) +
scale_y_continuous(limits = c(4,10)) +
theme_bw()
这给了我以下结果:
在创建自己的主题时,我可以使刻度线在内部或外部,但不能同时显示。
首先,似乎您已经知道:How do I make my axis ticks face Inwards in ggplot2
但是刻度线可以穿过轴吗? 结果,不,他们不能。
以下是ggplot2
Github repo中的相关文章。您会看到线段始终从轴开始绘制。
可能有一个ggplot2
扩展名可以简化此操作,但我不知道。