dom*_*woe 4 r time-series heatmap ggplot2
我有一个带有时间戳和值的数据框(一个月的值约为每5分钟).现在我想要绘制x轴上的日期,y轴上的时间和颜色的值.如果我可以控制y轴上的分箱(5分钟,10分钟,15分钟......值,作为每个箱的平均值),那将是最好的.
我正在试验ggplot2,但我无法得到合理的结果.
p_heat <- ggplot(data = data,
aes(x = days(timestamp),
y = minutes(timestamp) + hours(timestamp) * 60, fill = value)) +
geom_tile()
Run Code Online (Sandbox Code Playgroud)
测试数据可以如下生成:
data <- data.frame(timestamp = seq(from = as.POSIXct("2013-09-01 00:00:00"),
to = as.POSIXct("2013-10-01 00:00:00"), by = "5 mins"),
value = runif(8641, 0, 1))
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止最好的:)我也试过玩scale_x/y_date()
我会很高兴看到一些让我走向正确方向的暗示.谢谢!
你正在寻找这样的东西吗?
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
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
5392 次 |
| 最近记录: |