r中热图的GGplot桶着色
我有一些数据想转换成热图,就像这篇文章中的MSFT一样:r中热图的GGplot桶着色,r,ggplot2,R,Ggplot2,我有一些数据想转换成热图,就像这篇文章中的MSFT一样: Date temp week wday year 2013-01-02 -21 1 3 2013 2013-01-03 -22 1 4 2013 2013-01-04 -23 1 5 2013 2013-01-07 0 2 1 2013 2013-01-08 25 2 2 2013 2013-01-09 26 2 3 2013 2013-01-10 27 2
Date temp week wday year
2013-01-02 -21 1 3 2013
2013-01-03 -22 1 4 2013
2013-01-04 -23 1 5 2013
2013-01-07 0 2 1 2013
2013-01-08 25 2 2 2013
2013-01-09 26 2 3 2013
2013-01-10 27 2 4 2013
2013-01-11 28 2 5 2013
2013-01-14 29 3 1 2013
hmap=25
即通过4个十六进制代码立即而不是逐渐地进行更改使用cut
并进行分类设置。谢谢-我该怎么做?
Date temp week wday year
2013-01-02 -21 1 3 2013
2013-01-03 -22 1 4 2013
2013-01-04 -23 1 5 2013
2013-01-07 0 2 1 2013
2013-01-08 25 2 2 2013
2013-01-09 26 2 3 2013
2013-01-10 27 2 4 2013
2013-01-11 28 2 5 2013
2013-01-14 29 3 1 2013
hmap <- read.csv("heatmaptest.txt", as.is=TRUE)
hmap <- transform(hmap,
week = as.POSIXlt(Date)$yday %/% 7 + 1,
wday = as.POSIXlt(Date)$wday,
year = as.POSIXlt(Date)$year + 1900)
library(ggplot2)
ggplot(hmap, aes(week, wday, fill = temp)) +
geom_tile(colour = "white") +
scale_fill_gradientn(colours = c("#D61818","#FFAE63","#FFFFBD","#B5E384")) +
facet_wrap(~ year, ncol = 1)