0

I have two questions. I am using a dataset detailing information on Chicago (temp, ozone, season, date). I would like a plot show the temperature across time, along with a smooth line to show the trend, specifically with dates isolated from 1997-2000.

Thus:

library(ggplot2)
library(dplyr)
chicago <- read.csv(file = 'FilePath')

## Limit data to 1997-2000
chicago2 <- chicago %>%
  filter(date >= "1997-01-01" & date <= "2000-12-31")
  
ggplot(chicago2, aes(x=date, y=temp)) +
  geom_point() + 
  geom_smooth() +
  labs(title="Temperature")

My issues are as follows:

  1. There seems to be an issue with the x-axis, with the dates not cleanly represented. When I zoom into the picture, it seems like R is plotting every single date on the x-axis, but I am not sure if this is the actual issue. Scatterplot

  2. While I am able to accurately plot a scatterplot, there is no overlayed smooth line, despite the use of the geom_smooth() function.

Looking forward to your responses,

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Lior133
  • 13
  • 4
  • Try with converting your date to date format using e.g. `ggplot(chicago2, aes(x=as.Date(date), ...`. When doing so ggplot2 will automatically pick nice breaks for the x-axis. Additionally that should solve your geom_smooth issue. – stefan Oct 14 '21 at 17:36
  • Yessir! solved the problem perfectly. Cheers – Lior133 Oct 15 '21 at 00:23

0 Answers0