Plot timeseries as heatmap

假装没事ソ 提交于 2019-12-04 11:04:59

Is it something like this you are looking for?

library(ggplot2)   

# create date variable for the x-axis
df$date <- as.Date(df$timestamp, format = "%Y-%m-%d")

# get H:M components
df$hm <- format(df$timestamp, "%H:%M")    

# create y-axis breaks and labels
lab <- with(df, paste(format(df$timestamp, "%H"), "00", sep = ":"))

gg <- ggplot(data = df, aes(x = date, y = hm, fill = value)) +
  geom_tile() +
  scale_y_discrete(breaks = lab)

gg

Perhaps try this:

p_heat <- ggplot(data=data, aes(x=timestamp$mday ,y=timestamp$min+timestamp$hour*60)) 
    + stat_density2d(geom="tile", aes(fill = value), contour = FALSE)

Here's the relevent documentation: http://docs.ggplot2.org/current/stat_density2d.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!