首页 > 解决方案 > 如何在 R ggplot 中注释马赛克图?

问题描述

我的代码如下:

mtcars_tab <- mtcars %>% count(cyl, gear) # counts the number of gear / cylinder combinations
mtcars_tab %>% 
  ggplot() + 
    geom_mosaic(aes(x = product(gear), fill = cyl, weight = n), divider = mosaic("v")) +
    xlab("Gear") + 
    ylab("cyl") + 
  ggtitle("Distribution of Gears and Cylinders in the mtcars data")

我想在马赛克图的矩形(最好居中)上注释 n 这里。

当前地块

标签: rggplot2

解决方案


推荐阅读