0

I created a plot that ranges in date from 01-01-2012 to 12-31-2021. I've double checked the data to verify no dates before or after this interval, but my plot still shows the lines extending into 2011 and 2022. How can I fix my code to start and stop the line at exactly 2012 and 2021? Thanks!

plot1 <- lmic.clean7 %>% group_by(pubyear, Income) %>% dplyr::mutate(count = n()) %>% select(pubyear, Income, count) 
plot1$pubyear <- as.Date(plot1$pubyear, format = "%Y")
g2 <- ggplot(plot1, aes(x = pubyear, y = count, colour = Income)) + geom_smooth()
stefan
  • 90,330
  • 6
  • 25
  • 51
aml129
  • 25
  • 5
  • Hmm, I added it to the end after geom_smooth, but it still plots the same – aml129 Oct 08 '22 at 22:22
  • have you tried using `xlim(...)` It should allow you to set the range for your x-axis. Not sure if you need to put full dates on the dotted line or if only years work. – Douwe Oct 08 '22 at 22:25
  • Hm. Maybe you could provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. If you want to post your data type `dput(NAME_OF_DATASET)` into the console and copy the output starting with `structure(....` into your post. If your dataset has a lot of observations you could do e.g. `dput(head(NAME_OF_DATASET, 20))` for the first twenty rows of data. – stefan Oct 08 '22 at 22:27

0 Answers0