New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with date scale and Infinity (geom_segment) #4308
Comments
It works fine if you re-class the library(tidyverse)
library(lubridate)
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
set.seed(1234)
last_month <- ymd("2020-12-01") - 29:0
df <- data.frame(
date = last_month,
price = runif(30)
)
max_y = max(df$price)
max_x = df$date[df$price==max(df$price)][1]
base <- ggplot(df, aes(date, price)) +
geom_line(color="red")
base+
geom_segment(aes(x=max_x, xend=max_x,
y=structure(-Inf, class = "Date"), yend=max_y)) +
geom_segment(aes(x=structure(-Inf, class = "Date"), xend=max_x,
y=max_y, yend=max_y)) Created on 2021-01-05 by the reprex package (v0.3.0) |
Nice workaround as well! |
I agree that this is more of a scales issue, so I'm closing it here |
To emphasize a certain point, you might want to actually draw its coordinates using
geom_segment()
.When using
geom_segment()
, you can useInf
if the mapping so that the segment will start on the edge of the plot.However, if you use
Inf
like this on an axis of classDate
, it will throw an error:Here is an example with a simple workaround:
Created on 2021-01-05 by the reprex package (v0.3.0)
As you can see, adding a
scale_x_continuous()
call solves this issue without breaking the date labels so maybe this error is not mandatory.The text was updated successfully, but these errors were encountered: