简体   繁体   中英

Mosaic plot for a single variable in R like a puzzle not just vertical bars

How can I obtain something similar to a mosaic plot but representing just the information from a frequency table for a single variable?

mosaicplot(table(my_var)) works fine, but only shows vertical bars.

Is it possible to obtain a mosaic plot like a puzzle of different tiles instead of just vertical bars? Something similar to this image: 在此处输入图像描述

I had the same question, today. I found out that the graph is called treemap and at least two libraries support creating it: treemap and plotly .

As @Man.A noted, you can create a treemap with the treemap R package. A simple example:

# library
library(treemap)
#> Warning: package 'treemap' was built under R version 4.1.3

# Create data
group <- c("group-1","group-2","group-3")
value <- c(13,5,22)
data <- data.frame(group,value)

# treemap
treemap(data,
        index="group",
        vSize="value",
        type="index"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM