Forum Discussion

DatamindsMBM's avatar
DatamindsMBM
Frequent Visitor
9 years ago

Zooming in on RStudio (heat)maps

Hello community,

 

I am trying to use R with Power BI. In specifics, I would like my RStudio (heat)map to behave like any other Power BI map. When I choose to filter on a company (given that I'm using company data), or a region, the Power BI map zooms in on that particular spot. The R-visualization just filters and then stays at the same frame as before. in other words: it doesn't zoom in on what I filtered on.

 

I can't seem to find a solution to this anywhere, and I would therefore like to spark a discussion about this with the purpose of finding a solution.

Again, it is important for me to emphasize that I do not want a static view, but a dynamic view, which follows what I filter on.

 

Best regards,

Martin

Junior associate at Dataminds

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Martin,

    I've found you need to be very prescriptive with some of the R functions - e.g. defining specific xlim and ylim.  Can you provide some more details on your issue - the R functions and libraries you are trying to use, sample data etc., screenshots of the result you are getting?

    • DatamindsMBM's avatar
      DatamindsMBM
      Frequent Visitor

      Anonymous,

      I see. I can copy paste the syntax, which I already tried to use.

       

      library("ggmap", lib.loc="~/R/win-library/3.2")
      library("ggplot2", lib.loc="~/R/win-library/3.2")

      Country.map = get_map(location = "Location", zoom = 8, color="bw") ## get MAP data

      options(stringsAsFactors=T) ## need to run this --- weird ggplot bug=!

      p <- ggmap(Country.map)

      p <- p + stat_density_2d(bins=150, geom='polygon', size=2, data=dataset, aes(x = Longitude, y = Latitude, alpha=..level.., fill = ..level..))
      p <- p + scale_fill_gradient(low = "yellow", high = "red", guide=FALSE) + scale_alpha(range = c(0.02, 0.8), guide = FALSE) +xlab("") + ylab("")

      p + theme(axis.title=element_blank(),
      axis.text=element_blank(),
      axis.ticks=element_blank()) + ggtitle("Virksomheder")

       

      This is only my starting point. It might very we be, that this syntax is entirely wrong for what I am trying to do. The data varies. Its just a lot of company data. So there are name, address, city, Mother company, long., lat., Ownership, in which business it operates in, and so on. 

       

      If you need anymore information please ask me :) Please keep in mind that the result below is "ok". But I do not seek a static solution. When I filter on one particular region, I would like it to only show that, and most importantly, To zoom in that particular region. 

       

      Screenshot of current result:

       

      • alanhodgson's avatar
        alanhodgson
        Solution Supplier

        Hey DatamindsMBM,

         

        Check out this really interesting article here.

         

        The author uses the library "ggmap" to set the location range and zoom using this:

        library(ggmap)
        test <- get_map(location = 'chicago', zoom = 11)
        ggmap(test)

        Also, the article shows how to make a grid inside the map, so it doesn't looks so meshed together.

        You mentioned how you would like to zoom into a specific region when filtered, so maybe look to make the location dynamic and based off the city name.

         

         Hope this helps,

         

        Alan