我按照此website中显示的日历热图的示例(您必须向下滚动到日历热图部分)
使用网站上的示例:
library(ggplot2)
library(plyr)
library(scales)
library(zoo)
df <- read.csv("https://raw.githubusercontent.com/selva86/datasets/master/yahoo.csv")
df$date <- as.Date(df$date) # format date
df <- df[df$year >= 2012, ] # filter reqd years
# Create Month Week
df$yearmonth <- as.yearmon(df$date)
df$yearmonthf <- factor(df$yearmonth)
df <- ddply(df,.(yearmonthf), transform, monthweek=1+week-min(week)) # compute week number of month
df <- df[, c("year", "yearmonthf", "monthf", "week", "monthweek", "weekdayf", "VIX.Close")]
# Plot
ggplot(df, aes(monthweek, weekdayf, fill = VIX.Close)) +
geom_tile(colour = "white") +
facet_grid(year~monthf) +
scale_fill_gradient(low="red", high="green") +
labs(x="Week of Month",
y="",
title = "Time-Series Calendar Heatmap",
subtitle="Yahoo Closing Price",
fill="Close")
这是您获得的日历热图。
我可能会在这里特别挑剔,但有没有一种方法可以让条形符合刻面的网格线,同时将标签保持在中点?
我已经尝试过使用axis(),按照this这样的帖子提出建议,但是当我尝试将其翻译为日历热图时,我觉得有些东西会丢失。
任何建议都很棒,谢谢!