Closed dockstreet closed 6 years ago
Sorry about this. I messed up by not giving the latest release a new major version number, because it does contain some backwards-incompatible changes. In this case, the treemapify
function no longer takes xlim, ylim, group, label or fill arguments. Here's a version of the code you linked to modified for version 2.5:
library(ggplot2)
library(shiny)
library(tidyverse)
library(treemapify)
ui <- shinyUI(fluidPage(
titlePanel("Drill-down treemap"),
mainPanel(
plotOutput("graph", width = "100%", click = "tclick"),
actionButton("zoomout", "Zoom out")
)
))
server <- shinyServer(function(input, output, session) {
data <- G20
makeReactiveBinding('data')
output$graph <- renderPlot({
ggplot(data, aes(area = gdp_mil_usd, fill = hdi, subgroup = region, label = country)) +
geom_treemap() +
geom_treemap_text(reflow = T) +
geom_treemap_subgroup_text(grow = T, alpha = 0.5) +
geom_treemap_subgroup_border()
})
# When the 'Zoom out' button is clicked, reset the treemap
observeEvent(input$zoomout, {
data <<- G20
})
# When a subgroup is clicked
observeEvent(input$tclick, {
# Calculate coordinates of main treemap
coords <- treemapify(data, area = "gdp_mil_usd", subgroup = "region")
# Figure out which tile was clicked and what subgroup it belongs to
clickedSubgroup <- coords %>%
filter(xmin < input$tclick$x) %>%
filter(xmax > input$tclick$x) %>%
filter(ymin < input$tclick$y) %>%
filter(ymax > input$tclick$y) %>%
.$region
# Subset data to only that subgroup
data <<- data %>% filter(region == clickedSubgroup)
})
})
shinyApp(ui=ui,server=server)
If I roll back to 2.4 ; the very helpful drilldown example works
https://github.com/wilkox/treemapify/issues/22
but in 2.5 are not passed and xmin/ymin do not function and errors out
xlim = c(0, 1), ylim = c(0, 1)
other parameters are warnings and deprecated if I update to what is currently 2.5.90001