I'm trying to make a heatmap on ggplot. I have a data frame similar to the one below
wday hour quant
Mon 0 1.2346944
Tue 0 0.8418860
Wed 0 0.8904375
Thu 0 0.8906767
Fri 0 1.0761553
Sat 0 2.1095617
Sun 0 2.1421696
Mon 1 2.9178615
Tue 1 0.7481875
Wed 1 0.6200556
Thu 1 0.5530000
Fri 1 0.3852611
Sat 1 0.4791192
Sun 1 1.0958043
Mon 2 2.8627222
Tue 2 0.7989769
Wed 2 0.4209105
Thu 2 0.6512810
Fri 2 0.5047176
Sat 2 0.6544059
Sun 2 0.8167846
And my code is :
ggplot(df , aes(x = hour, y = wday)) +
geom_raster(aes(fill = quant), interpolate=TRUE) +
scale_fill_distiller(palette = "Spectral") +
theme(legend.position = "bottom")
it renders a graph like that :
You can see that the colorbar of the legend is really contracted, how can I extend the legend horizontally so it becomes wider?
legend.key.width
is what you want. For instance,
ggplot(df , aes(x = hour, y = wday)) +
geom_raster(aes(fill = quant), interpolate = TRUE) +
scale_fill_distiller(palette = "Spectral") +
theme(legend.position = "bottom", legend.key.width = unit(2.5, "cm"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With