0

I've just did the following graph:

enter image description here

But juny 22 is not the last date available. How can I plot this graph from des. 19 to the most recent date?

plot2 <- ggplot(taxa_atur, aes(x=time, y=values, color= geo, group=geo))+
  geom_line(linewidth=1, aes(linetype = (geo == "EA19")))+
  guides(linetype = "none")+
  scale_y_continuous(expand=c(0,0), limits=as.numeric(c(5,10)), breaks=seq(from=5, to=10, by=1)) + 
  scale_x_date(expand=c(0,0), breaks = seq(from = as.Date("2019-12-01"), to = as.Date("2022-06-01"), by = "2 months"), labels=date_format("%b %y"),
               limits = c(as.Date("2019-12-01"), as.Date("2022-06-01"))))

I know that I have specified to be graphed to "2022-06-01", but how can I code graph it to the most recent date?

structure(list(s_adj = c("SA", "SA", "SA", "SA", "SA"), age = c("Y25-74", 
"Y25-74", "Y25-74", "Y25-74", "Y25-74"), unit = c("PC_ACT", "PC_ACT", 
"PC_ACT", "PC_ACT", "PC_ACT"), sex = c("T", "T", "T", "T", "T"
), geo = c("EA20", "ES", "EU27_2020", "FR", "EA20"), time = structure(c(19358, 
19358, 19358, 19358, 19327), class = "Date"), values = c(5.9, 
11.7, 5.3, 5.8, 5.9)), row.names = c(NA, -5L), class = c("tbl_df", 
"tbl", "data.frame"))
Maria
  • 173
  • 7
  • Why not just remove `limits = c(as.Date("2019-12-01"), as.Date("2022-06-01"))`? As an aside, using the `limits` option in a `scale_xxxxx` call is potentially dangerous as it filters the input before constructing the graph. `coord_cartesian` is safer as it uses the whole of the input and then "zooms" to the appropriate region. – Limey Mar 02 '23 at 14:13
  • 1
    If you wan to limit the first instance then you can un-limit the upper end by passing NA: `limits = c(as.Date("2019-12-01"), NA)`. Or use `ylim` in `coord_cartesian` as noted by @Limey – Andy Baxter Mar 02 '23 at 14:17
  • Or subset your data rather than using plot options. `taxa_atur |> subset(time >= as.Date("2019-12-01")) |> ggplot(aes(x=time, y=values, color= geo, group=geo)) + ...`, deleting the `limits` entirely. – Gregor Thomas Mar 02 '23 at 14:36

0 Answers0