R ggplot2热图与日期x轴 - 删除灰色区域

问题描述 投票:1回答:1

我正在尝试显示西欧一个家庭用电能耗的热图,在X轴上是Y轴每年的所有日子,每天的小时数,热图显示用电量为千瓦时每小时每天。这是我到目前为止所得到的:Heat map Energy consumption我的问题是缩放日期X轴,使得图表左侧和右侧的灰色条带消失。知道如何扩展(),即将数据显示限制为数字数据的最小值,最大值,证明很难找到x轴日期的解决方案。

这是我用来提供以上情节的内容:

hm.palette <- colorRampPalette(rev(brewer.pal(11, 'Spectral')), space='Lab')
heatmap_print <- ggplot(MyData, aes(y=Time, x=Day, fill=Totaal)) + 
geom_tile(aes(height=1)) +
scale_fill_gradientn(colours = hm.palette(100)) 
print(heatmap_print + 
    scale_y_continuous(name = "Hour of day", breaks = seq(0, 23, by=1), expand = c(0, 0)) + 
    scale_x_date(name = "Month of year", 
                 breaks = seq(as.Date("2009-01-15"), 
                              as.Date("2009-12-15"), 
                              by = "1 month"), date_labels ="%B"))

感恩,任何想法。

r ggplot2 heatmap
1个回答
1
投票

如果你只是想摆脱灰色,尝试使用themes()这样的东西:

hm.palette <- colorRampPalette(rev(brewer.pal(11, 'Spectral')), space='Lab')
heatmap_print <- ggplot(MyData, aes(y=Time, x=Day, fill=Totaal)) + 
geom_tile(aes(height=1)) +
scale_fill_gradientn(colours = hm.palette(100)) 
print(heatmap_print + 
    scale_y_continuous(name = "Hour of day", breaks = seq(0, 23, by=1), expand = c(0, 0)) + 
    scale_x_date(name = "Month of year", 
                 breaks = seq(as.Date("2009-01-15"), 
                              as.Date("2009-12-15"), 
                              by = "1 month"), date_labels ="%B")) +
    theme(panel.background = element_blank(),
          plot.background = element_blank())

否则,你需要考虑使用coord_cartesian(xlim = c(X, X), ylim = c(X, X))或只是简单的xlim(X, X) + ylim(X, X)

© www.soinside.com 2019 - 2024. All rights reserved.