[英]How to make mosaic plot in ggplot2
我想在 ggplot2 中制作马赛克 plot,by geom_mosaic
我想在ggplot2中制作马赛克plot。这将与此相同。
library(faraway)
(ct <- xtabs(y ~ right + left, eyegrade))
mosaicplot(ct, color = c("lightblue"),xlab="Right eye",ylab="Left eye")
我有数据框 eyegrade,但我不知道如何设置 aes。
library(ggplot2)
library(ggmosaic)
ggplot(data = eyegrade) +
geom_mosaic(aes(x = product(left,right)))
谢谢你
原始马赛克图如下所示:
library(faraway)
ct <- xtabs(y ~ right + left, eyegrade)
mosaicplot(ct, color = c("lightblue"), xlab = "Right eye", ylab = "Left eye")
ggmosaic 中的等价物是这样的:
library(ggplot2)
library(ggmosaic)
ggplot(data = within(eyegrade, left <- forcats::fct_rev(left))) +
geom_mosaic(aes(x = product(left, right), weight = y),
fill = "lightblue", color = "black") +
scale_x_productlist(position = "top", expand = c(0, 0)) +
scale_y_productlist(expand = c(0, 0)) +
theme_minimal(base_size = 16) +
theme(panel.grid = element_blank())
创建于 2022-11-26,使用reprex v2.0.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.