1

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:enter image description here

2 Answers2

2

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.

Man.A.
  • 31
  • 3
0

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"
)

socialscientist
  • 3,759
  • 5
  • 23
  • 58