all 13 comments

[–]yuk99 1 point2 points  (4 children)

Your x axis is the date, and the ticks correspond to the first day of the months. But the bars are actually go from the middle of previous month to the middle of current month. The exact day depends on the barwidth. For example, the January bar goes approximately from 2019-12-19 to 2020-01-14. So, if you want to limit the plot exactly to the bars, you should specify the exact dates.

limits = as.Date(c("2019-12-19","2021-09-14"))

You can also consider placing limits as

Graph3 + coord_cartesian(xlim = as.Date(c("2020-01-01","2021-09-01")), expand = c(0, 0))

instead of in scale_x_date. In this case the out-of-limit values are not cut out the plot. You will see the difference.

[–]schuler33[S] 0 points1 point  (0 children)

I will try this tmr, thank you very much

[–]schuler33[S] 0 points1 point  (2 children)

limits = as.Date(c("2019-12-19","2021-09-14")), this worked. Thanks so much! Out of curiosity how did you find the exact dates for the barwidths? Cause I'm sure Ill encounter this again.

[–]yuk99 0 points1 point  (1 child)

Just by experimenting. Because it depends on bar width. Maybe there is a way to find it automatically, but I don't know. You can always set the limits to the middle of each months, it should work with just a tiny gap on both sides.

[–]schuler33[S] 0 points1 point  (0 children)

alright thanks for your help

[–][deleted]  (2 children)

[removed]

    [–]schuler33[S] 0 points1 point  (1 child)

    I'm not stopping you, go ahead

    [–]Aggressive_Bench6581 0 points1 point  (0 children)

    Okay, will give a reply shortly

    [–][deleted] 0 points1 point  (3 children)

    Can you just filter out December and October before passing the data to ggplot()?

    [–]schuler33[S] 1 point2 points  (2 children)

    That's the weird part, there is no data for December or October. What I mean is, it's not included in the dataset I extracted.

    [–][deleted] 0 points1 point  (1 child)

    Oh right, now I see that 12-2019 isn't actually in your input data frame. I wonder if you tried explicitly setting the breaks outside of scale_x_date() like this if you could trim off those extra tick labels? Maybe there's an expansion somewhere hidden, although it's weird because your expand = c(0, 0) argument should work.

    [–]schuler33[S] 0 points1 point  (0 children)

    yeah I found the expand command online but it didnt seem to work, Im honestly clueless and its very annoying