我正在尝试使用ggvis从ggplot2中复制带有数字的热力图。ggplot2版本为
library(ggplot2)
hec <- as.data.frame(xtabs(Freq ~ Hair + Eye, HairEyeColor))
ggplot(hec, aes(Hair, Eye)) +
geom_tile(aes(fill = Freq)) +
geom_text(aes(label = Freq),colour="white")
看起来是这个样子的
我在ggvis中的版本为
hec%>%
ggvis(~Hair, ~Eye, fill=~Freq)%>%
layer_rects(width = band(), height = band()) %>%
layer_text(text:=~Freq,fontSize := 20, fill:="white",baseline:="top",align:="center") %>%
scale_nominal("x", padding = 0, points = FALSE) %>%
scale_nominal("y", padding = 0, points = FALSE)
结果并不完美。
我尝试通过手动添加边距来修复数字对齐问题,但这种情况无法调整大小。
有什么想法吗?