Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use geom_tile() or
geom_raster() and map a continuous
variable to fill. We’ll use the
presidents data set, which is a time
series object rather than a data frame:
presidentsQtr1 Qtr2 Qtr3 Qtr4str1945NA878275194663504332...197368444027197428252424(presidents)Time-Series[1:120]from1945to1975:NA878275635043323560...
We’ll first convert it to a format that is usable by ggplot()—a data
frame with columns that are numeric:
pres_rating<-data.frame(rating=as.numeric(presidents),year=as.numeric(floor(time(presidents))),quarter=as.numeric(cycle(presidents)))pres_ratingrating year quarterNA1945187194528219453...251974224197432419744