I am currently experimentating with treemap plots with apexcharter
and I am trying to replicate some functionnalities that I used in my previous plots.
1 – I would like to display the y value (or the percentage of that y value like in a pie plot) below the x label. I only found that graph which seems to do that, but I can’t seem to be able to reproduce it in R. You can find my attempt to replicate it in the ax_dataLabels()
function.
2 – The colors displayed in the distributed treemap are not the ones I defined in ax_colors()
, or rather they seem to be gradients between them. I wonder what causes this and how I can force the chart to use exactly the ones defined.
There doesn’t seem to be a lot documentation of apexcharter treemaps in R and it looks like they need to be configured a bit differentrly from the pie and bar charts.
Here is the code used :
library(tidyverse)
library(apexcharter)
dummy_data <- tibble(
Material = c("Lead", "Tin", "Iron", "Copper", "Mercury", "Silver", "Gold"),
Quantities = c(18, 15, 12, 10, 11, 40, 100)
)
apex(dummy_data, type = "treemap", mapping = aes(x = Material, y = Quantities)) %>%
ax_colors(c('#001219', '#005F73', '#0A9396', '#E9D8A6', '#EE9B00', '#CA6702', '#BB3E03')) %>%
ax_dataLabels(
enabled = TRUE,
style = list(
fontSize = "18px",
formatter = JS("function(text, op) {
return [text, op.value]
}")
)) %>%
ax_plotOptions(treemap = list(distributed = TRUE)) %>%
ax_chart(toolbar = FALSE)