You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error with date scale and Infinity (geom_segment) #4308
It works fine if you re-class the -Inf to a Date class, but it is a bit of an inconvenient workaround.
Some time ago I opened an issue in the scales package suggesting that the date transformation be allowed some more flexibility around numeric input, which might help these kind of issues.
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:0df<-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))
Nice workaround as well!
This is actually much better than my way of doing it, as you can declare date_minf = structure(-Inf, class = "Date") and use it freely in the mapping.
Activity
teunbrand commentedon Jan 5, 2021
It works fine if you re-class the
-Infto aDateclass, but it is a bit of an inconvenient workaround.Some time ago I opened an issue in the scales package suggesting that the date transformation be allowed some more flexibility around numeric input, which might help these kind of issues.
Created on 2021-01-05 by the reprex package (v0.3.0)
DanChaltiel commentedon Jan 5, 2021
Nice workaround as well!
This is actually much better than my way of doing it, as you can declare
date_minf = structure(-Inf, class = "Date")and use it freely in the mapping.thomasp85 commentedon Mar 24, 2021
I agree that this is more of a scales issue, so I'm closing it here