[R] ggplot2 / time series with different scales

Chuck White chuckwhite8 at charter.net
Fri Feb 5 20:46:24 CET 2010

Thank you both for your response.  As the names suggest, I am plotting the sales & price data for items over time to understand the how certain items may be more responsive than others to price changes.

Another way of displaying this information on the same chart as the one showing sales, would be to scale the price data between 0 and 1 (1 - current_price/max_price) and use a geom_tile (?) to display it. In terms of the axes, x axis would still be time, y axis would be constant (top of the chart) and fill would change based on the scaled price (i.e. discount).

Would it be possible to do this in ggplot2?

df <- melt(df, id=c('time', 'sid'))
ggplot(df, aes(time, value, colour=sid)) +
   geom_line(data = subset(df, variable=='sales')) +
   geom_point(data = subset(df, variable=='price')) +  <--- replace with geom_tile?
   facet_wrap(~sid + variable, ncol=1, scales='free_y') 


More information about the R-help mailing list