I am working with the R programming language.
I am trying to follow the answers provided over here: Treemap plot with plotly in R
I made my own dataset for this problem:
library(treemap)
library(plotly)
library(dplyr)
library(stringr)
########################
var1 <- c("A", "B", "C", "D", "E")
var1<- sample(var1, 1000, replace=TRUE, prob=c(0.2, 0.2, 0.2, 0.2, 0.2))
var1<- as.factor(var1)
var2 <- c("abc", "bcd", "egf", "hiu", "lkj", "oiu", "piu", "xsr", "zze", "tre")
var2<- sample(var2, 1000, replace=TRUE, prob=c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1))
var2<- as.factor(var2)
my_data = data.frame(var1, var2)
my_data = data.frame(my_data %>% group_by(var1, var2) %>% summarise(counts = n()))
Then, I tried to adapt the answers provided in this link (Treemap plot with plotly in R) to recreate these visualizations for my data:
# visualization 1
(g4EMP1 <- plot_ly(
data = my_data,
type = "treemap",
labels = ~var2 %>% stringr::str_wrap(width = 15),
branchvalues = "total",
values = ~counts,
parents = ~var1))
# visualization 2
(g4EMP2 <- plot_ly(
data = my_data,
type = "treemap",
labels = ~var2%>% stringr::str_wrap(width = 15),
#values = ~size,
parents = ~var1)) %>%
layout(uniformtext = list(minsize = 10))
However, when I try to view these plots - all I see is a blank screen?
Can someone please show me what I am doing wrong and what can I do to fix this?
Thanks!