heatmap with values and some additional features in R [duplicate]

依然范特西╮ 提交于 2019-12-04 22:48:42

We just need to rearrange the data into a long format. Then plot, making sure we only give a subset of the data to geom_tile. Then we rearrange the axis ordering.

library(ggplot2)

dat2 <- stack(dat[-1])
dat2$year <- dat$Year

ggplot(mapping = aes(ind, year)) +
  geom_tile(aes(fill = values), subset(dat2, year != "Average" & ind != "Sum")) +
  geom_text(aes(label = round(values, 1)), dat2) +
  scale_y_discrete(limits = c("Average", 2017:1999)) +
  scale_x_discrete(limits = c(month.abb, "Sum"), position = "top") +
  viridis::scale_fill_viridis() +
  theme_minimal() + theme(axis.title = element_blank())

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!