1

I'm using RStudio. I have a dataframe called data.

I've plotted these variables separately:

data_tmp<-xts(as.matrix(data[,-1]), order.by = data$date)

autoplot(data_tmp$sales)

autoplot(data_tmp$temperature)

I would like to combine the variables "sales" and "temperature" in a single graph, with a different colour for each variable, so I can check the seasonality and if they are correlated. The problem that I'm facing is the differences in the scale. I would like to create two 'y' axis so both variables are with the same scale.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Jusep
  • 187
  • 8
  • Creating two y-axis in ggplot2 was (in the past) considered a bit of a workaround. This post might give you what you need though: https://stackoverflow.com/questions/3099219/ggplot-with-2-y-axes-on-each-side-and-different-scales – Harrison Jones Sep 21 '21 at 13:12

0 Answers0