When I combine geom_vline
and coord_polar
with a Date
axis, it asks for origin. It works fine when coord_polar
is not called.
library(ggplot2)
data.frame(
a = seq.Date(as.Date("2022-01-01"), as.Date("2022-01-31"), by= "1 day"),
b = runif(31)
) |>
ggplot(aes(x=a, y=1, fill=b))
geom_tile(show.legend = FALSE)
geom_vline(xintercept=as.Date("2022-01-15"))
coord_polar()
#> Error in as.Date.numeric(value): 'origin' must be supplied
Created on 2022-11-07 with reprex v2.0.2
What is origin in this context?
CodePudding user response:
I think coord_polar()
is not equipped for working with dates. Just transform the xintercept
to numeric and it should just work (TM):
library(ggplot2)
data.frame(
a = seq.Date(as.Date("2022-01-01"), as.Date("2022-01-31"), by= "1 day"),
b = runif(31)
) |>
ggplot(aes(x=a, y=1, fill=b))
geom_tile(show.legend = FALSE)
geom_vline(xintercept=as.numeric(as.Date("2022-01-15")), size=2, color="red")
coord_polar()
Created on 2022-11-07 with reprex v2.0.2
Btw I really hope this is just a MVE, a circular graph with dates looks really confusing imo.