How to change the attribute table popup/hover text in a plotly map





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to make an interactive plotly map from a shapefile, with a hover/tooltip that shows some information.



Currently when I hover over an area on the map it only gives the information for VAR1 (A,B,C,D) rather than the information in DATA$HOVER



The map (Called NUTS1 in my code) is obtained from: http://geoportal.statistics.gov.uk/datasets/nuts-level-1-january-2018-full-clipped-boundaries-in-the-united-kingdom)



I do not have access to SF.




sessionInfo()

R version 3.4.0 Patched (2017-05-31 r72750)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows 7 x64 (build 7601) Service Pack 1


packageVersion("plotly")

[1] ‘4.7.1’


packageVersion("ggplot2")

[1] ‘2.2.1’




DATA <- c(NA)
DATA$NUTS1 <- c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM",
"UKN")
DATA$VAR1 <- c("D","D","A","D","A","C","B","C","B","C","B","A")
DATA$VAR2 <- c("8","4","1","10","4","7","5","1","8","6","3","8")
DATA$VAR3 <- c("1","2","3","4","5","6","7","8","9","10","11","12")
NUTS1 <- readOGR(dsn =
"NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
layer =
"NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
NUTS1 <- fortify(NUTS1, region = "nuts118cd")
DATA$HOVER <- with(DATA, paste(NUTS1, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

p <- ggplot(data = DATA, text = HOVER) +
geom_map(data = DATA, aes(map_id = NUTS1, fill = VAR1), map = NUTS1) +
expand_limits(x = NUTS1$long, y = NUTS1$lat)

p <- ggplotly(p, tooltip = "text")









share|improve this question































    0















    I am trying to make an interactive plotly map from a shapefile, with a hover/tooltip that shows some information.



    Currently when I hover over an area on the map it only gives the information for VAR1 (A,B,C,D) rather than the information in DATA$HOVER



    The map (Called NUTS1 in my code) is obtained from: http://geoportal.statistics.gov.uk/datasets/nuts-level-1-january-2018-full-clipped-boundaries-in-the-united-kingdom)



    I do not have access to SF.




    sessionInfo()

    R version 3.4.0 Patched (2017-05-31 r72750)

    Platform: x86_64-w64-mingw32/x64 (64-bit)

    Running under: Windows 7 x64 (build 7601) Service Pack 1


    packageVersion("plotly")

    [1] ‘4.7.1’


    packageVersion("ggplot2")

    [1] ‘2.2.1’




    DATA <- c(NA)
    DATA$NUTS1 <- c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM",
    "UKN")
    DATA$VAR1 <- c("D","D","A","D","A","C","B","C","B","C","B","A")
    DATA$VAR2 <- c("8","4","1","10","4","7","5","1","8","6","3","8")
    DATA$VAR3 <- c("1","2","3","4","5","6","7","8","9","10","11","12")
    NUTS1 <- readOGR(dsn =
    "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
    layer =
    "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
    NUTS1 <- fortify(NUTS1, region = "nuts118cd")
    DATA$HOVER <- with(DATA, paste(NUTS1, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

    p <- ggplot(data = DATA, text = HOVER) +
    geom_map(data = DATA, aes(map_id = NUTS1, fill = VAR1), map = NUTS1) +
    expand_limits(x = NUTS1$long, y = NUTS1$lat)

    p <- ggplotly(p, tooltip = "text")









    share|improve this question



























      0












      0








      0








      I am trying to make an interactive plotly map from a shapefile, with a hover/tooltip that shows some information.



      Currently when I hover over an area on the map it only gives the information for VAR1 (A,B,C,D) rather than the information in DATA$HOVER



      The map (Called NUTS1 in my code) is obtained from: http://geoportal.statistics.gov.uk/datasets/nuts-level-1-january-2018-full-clipped-boundaries-in-the-united-kingdom)



      I do not have access to SF.




      sessionInfo()

      R version 3.4.0 Patched (2017-05-31 r72750)

      Platform: x86_64-w64-mingw32/x64 (64-bit)

      Running under: Windows 7 x64 (build 7601) Service Pack 1


      packageVersion("plotly")

      [1] ‘4.7.1’


      packageVersion("ggplot2")

      [1] ‘2.2.1’




      DATA <- c(NA)
      DATA$NUTS1 <- c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM",
      "UKN")
      DATA$VAR1 <- c("D","D","A","D","A","C","B","C","B","C","B","A")
      DATA$VAR2 <- c("8","4","1","10","4","7","5","1","8","6","3","8")
      DATA$VAR3 <- c("1","2","3","4","5","6","7","8","9","10","11","12")
      NUTS1 <- readOGR(dsn =
      "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
      layer =
      "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
      NUTS1 <- fortify(NUTS1, region = "nuts118cd")
      DATA$HOVER <- with(DATA, paste(NUTS1, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

      p <- ggplot(data = DATA, text = HOVER) +
      geom_map(data = DATA, aes(map_id = NUTS1, fill = VAR1), map = NUTS1) +
      expand_limits(x = NUTS1$long, y = NUTS1$lat)

      p <- ggplotly(p, tooltip = "text")









      share|improve this question
















      I am trying to make an interactive plotly map from a shapefile, with a hover/tooltip that shows some information.



      Currently when I hover over an area on the map it only gives the information for VAR1 (A,B,C,D) rather than the information in DATA$HOVER



      The map (Called NUTS1 in my code) is obtained from: http://geoportal.statistics.gov.uk/datasets/nuts-level-1-january-2018-full-clipped-boundaries-in-the-united-kingdom)



      I do not have access to SF.




      sessionInfo()

      R version 3.4.0 Patched (2017-05-31 r72750)

      Platform: x86_64-w64-mingw32/x64 (64-bit)

      Running under: Windows 7 x64 (build 7601) Service Pack 1


      packageVersion("plotly")

      [1] ‘4.7.1’


      packageVersion("ggplot2")

      [1] ‘2.2.1’




      DATA <- c(NA)
      DATA$NUTS1 <- c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM",
      "UKN")
      DATA$VAR1 <- c("D","D","A","D","A","C","B","C","B","C","B","A")
      DATA$VAR2 <- c("8","4","1","10","4","7","5","1","8","6","3","8")
      DATA$VAR3 <- c("1","2","3","4","5","6","7","8","9","10","11","12")
      NUTS1 <- readOGR(dsn =
      "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
      layer =
      "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
      NUTS1 <- fortify(NUTS1, region = "nuts118cd")
      DATA$HOVER <- with(DATA, paste(NUTS1, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

      p <- ggplot(data = DATA, text = HOVER) +
      geom_map(data = DATA, aes(map_id = NUTS1, fill = VAR1), map = NUTS1) +
      expand_limits(x = NUTS1$long, y = NUTS1$lat)

      p <- ggplotly(p, tooltip = "text")






      r ggplot2 hover tooltip r-plotly






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 6 at 0:13









      Valentin

      2,2421632




      2,2421632










      asked Jan 3 at 15:57









      Aaron WaltonAaron Walton

      394




      394
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I think, first of all, your DATA object should be a data.frame (from your code I get a list, which is no accepted by the ggplot() function).



          Then, try to map the column HOVER into the text aesthetic in geom_map() and not in ggplot().



          Also, in your DATA data.frame, rename the column NUTS1 to id, so that it matches the column name id from NUTS1 data.frame obtained with fortify (you see that this is important from the examples found in help(geom_map)).



          library(ggplot2)
          library(plotly)
          library(rgdal)

          DATA <- data.frame(id = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          DATA$HOVER <- with(DATA, paste(id, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
          NUTS1 <- fortify(NUTS1, region = "nuts118cd")

          p <- ggplot(data = DATA) +
          geom_map(aes(map_id = id, fill = VAR1, text = HOVER), map = NUTS1) +
          expand_limits(x = NUTS1$long, y = NUTS1$lat)

          p2 <- ggplotly(p)
          p2


          enter image description here





          Note that, interactive maps are more straightforward to make with the mapview package. For your particular issue, check mapview popups. Here is an attempt with mapview:



          library(mapview)
          library(rgdal)

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")

          DATA <- data.frame(NUTS1 = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          # merge DATA with the SpatialPolygonsDataFrame NUTS1
          nuts <- merge(x = NUTS1, y = DATA, by.x = "nuts118cd", by.y = "NUTS1")

          mapview(nuts, popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))


          enter image description here



          To fill by VAR1, you need to follow this example and call zcol = "VAR1" in mapview, like:



          mapview(nuts, zcol = "VAR1", 
          popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))





          share|improve this answer


























          • That worked perfectly!

            – Aaron Walton
            Jan 8 at 10:19











          • Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

            – Valentin
            Jan 8 at 10:33














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025734%2fhow-to-change-the-attribute-table-popup-hover-text-in-a-plotly-map%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I think, first of all, your DATA object should be a data.frame (from your code I get a list, which is no accepted by the ggplot() function).



          Then, try to map the column HOVER into the text aesthetic in geom_map() and not in ggplot().



          Also, in your DATA data.frame, rename the column NUTS1 to id, so that it matches the column name id from NUTS1 data.frame obtained with fortify (you see that this is important from the examples found in help(geom_map)).



          library(ggplot2)
          library(plotly)
          library(rgdal)

          DATA <- data.frame(id = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          DATA$HOVER <- with(DATA, paste(id, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
          NUTS1 <- fortify(NUTS1, region = "nuts118cd")

          p <- ggplot(data = DATA) +
          geom_map(aes(map_id = id, fill = VAR1, text = HOVER), map = NUTS1) +
          expand_limits(x = NUTS1$long, y = NUTS1$lat)

          p2 <- ggplotly(p)
          p2


          enter image description here





          Note that, interactive maps are more straightforward to make with the mapview package. For your particular issue, check mapview popups. Here is an attempt with mapview:



          library(mapview)
          library(rgdal)

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")

          DATA <- data.frame(NUTS1 = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          # merge DATA with the SpatialPolygonsDataFrame NUTS1
          nuts <- merge(x = NUTS1, y = DATA, by.x = "nuts118cd", by.y = "NUTS1")

          mapview(nuts, popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))


          enter image description here



          To fill by VAR1, you need to follow this example and call zcol = "VAR1" in mapview, like:



          mapview(nuts, zcol = "VAR1", 
          popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))





          share|improve this answer


























          • That worked perfectly!

            – Aaron Walton
            Jan 8 at 10:19











          • Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

            – Valentin
            Jan 8 at 10:33


















          1














          I think, first of all, your DATA object should be a data.frame (from your code I get a list, which is no accepted by the ggplot() function).



          Then, try to map the column HOVER into the text aesthetic in geom_map() and not in ggplot().



          Also, in your DATA data.frame, rename the column NUTS1 to id, so that it matches the column name id from NUTS1 data.frame obtained with fortify (you see that this is important from the examples found in help(geom_map)).



          library(ggplot2)
          library(plotly)
          library(rgdal)

          DATA <- data.frame(id = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          DATA$HOVER <- with(DATA, paste(id, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
          NUTS1 <- fortify(NUTS1, region = "nuts118cd")

          p <- ggplot(data = DATA) +
          geom_map(aes(map_id = id, fill = VAR1, text = HOVER), map = NUTS1) +
          expand_limits(x = NUTS1$long, y = NUTS1$lat)

          p2 <- ggplotly(p)
          p2


          enter image description here





          Note that, interactive maps are more straightforward to make with the mapview package. For your particular issue, check mapview popups. Here is an attempt with mapview:



          library(mapview)
          library(rgdal)

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")

          DATA <- data.frame(NUTS1 = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          # merge DATA with the SpatialPolygonsDataFrame NUTS1
          nuts <- merge(x = NUTS1, y = DATA, by.x = "nuts118cd", by.y = "NUTS1")

          mapview(nuts, popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))


          enter image description here



          To fill by VAR1, you need to follow this example and call zcol = "VAR1" in mapview, like:



          mapview(nuts, zcol = "VAR1", 
          popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))





          share|improve this answer


























          • That worked perfectly!

            – Aaron Walton
            Jan 8 at 10:19











          • Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

            – Valentin
            Jan 8 at 10:33
















          1












          1








          1







          I think, first of all, your DATA object should be a data.frame (from your code I get a list, which is no accepted by the ggplot() function).



          Then, try to map the column HOVER into the text aesthetic in geom_map() and not in ggplot().



          Also, in your DATA data.frame, rename the column NUTS1 to id, so that it matches the column name id from NUTS1 data.frame obtained with fortify (you see that this is important from the examples found in help(geom_map)).



          library(ggplot2)
          library(plotly)
          library(rgdal)

          DATA <- data.frame(id = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          DATA$HOVER <- with(DATA, paste(id, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
          NUTS1 <- fortify(NUTS1, region = "nuts118cd")

          p <- ggplot(data = DATA) +
          geom_map(aes(map_id = id, fill = VAR1, text = HOVER), map = NUTS1) +
          expand_limits(x = NUTS1$long, y = NUTS1$lat)

          p2 <- ggplotly(p)
          p2


          enter image description here





          Note that, interactive maps are more straightforward to make with the mapview package. For your particular issue, check mapview popups. Here is an attempt with mapview:



          library(mapview)
          library(rgdal)

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")

          DATA <- data.frame(NUTS1 = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          # merge DATA with the SpatialPolygonsDataFrame NUTS1
          nuts <- merge(x = NUTS1, y = DATA, by.x = "nuts118cd", by.y = "NUTS1")

          mapview(nuts, popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))


          enter image description here



          To fill by VAR1, you need to follow this example and call zcol = "VAR1" in mapview, like:



          mapview(nuts, zcol = "VAR1", 
          popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))





          share|improve this answer















          I think, first of all, your DATA object should be a data.frame (from your code I get a list, which is no accepted by the ggplot() function).



          Then, try to map the column HOVER into the text aesthetic in geom_map() and not in ggplot().



          Also, in your DATA data.frame, rename the column NUTS1 to id, so that it matches the column name id from NUTS1 data.frame obtained with fortify (you see that this is important from the examples found in help(geom_map)).



          library(ggplot2)
          library(plotly)
          library(rgdal)

          DATA <- data.frame(id = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          DATA$HOVER <- with(DATA, paste(id, "<br>", VAR1, "<br>", VAR2, "<br>", VAR3))

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")
          NUTS1 <- fortify(NUTS1, region = "nuts118cd")

          p <- ggplot(data = DATA) +
          geom_map(aes(map_id = id, fill = VAR1, text = HOVER), map = NUTS1) +
          expand_limits(x = NUTS1$long, y = NUTS1$lat)

          p2 <- ggplotly(p)
          p2


          enter image description here





          Note that, interactive maps are more straightforward to make with the mapview package. For your particular issue, check mapview popups. Here is an attempt with mapview:



          library(mapview)
          library(rgdal)

          NUTS1 <- readOGR(dsn = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom",
          layer = "NUTS_Level_1_January_2018_Full_Clipped_Boundaries_in_the_United_Kingdom")

          DATA <- data.frame(NUTS1 = c("UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"),
          VAR1 = c("D","D","A","D","A","C","B","C","B","C","B","A"),
          VAR2 = c("8","4","1","10","4","7","5","1","8","6","3","8"),
          VAR3 = 1:12)
          # merge DATA with the SpatialPolygonsDataFrame NUTS1
          nuts <- merge(x = NUTS1, y = DATA, by.x = "nuts118cd", by.y = "NUTS1")

          mapview(nuts, popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))


          enter image description here



          To fill by VAR1, you need to follow this example and call zcol = "VAR1" in mapview, like:



          mapview(nuts, zcol = "VAR1", 
          popup = popupTable(nuts, zcol = c("nuts118cd", "VAR1", "VAR2", "VAR3")))






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 7 at 12:34

























          answered Jan 5 at 22:50









          ValentinValentin

          2,2421632




          2,2421632













          • That worked perfectly!

            – Aaron Walton
            Jan 8 at 10:19











          • Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

            – Valentin
            Jan 8 at 10:33





















          • That worked perfectly!

            – Aaron Walton
            Jan 8 at 10:19











          • Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

            – Valentin
            Jan 8 at 10:33



















          That worked perfectly!

          – Aaron Walton
          Jan 8 at 10:19





          That worked perfectly!

          – Aaron Walton
          Jan 8 at 10:19













          Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

          – Valentin
          Jan 8 at 10:33







          Hi @AaronWalton, Nice! Glad that I could help. Consider marking the answer as accepted (and eventually vote on it) as per this and this SO guidelines.

          – Valentin
          Jan 8 at 10:33






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025734%2fhow-to-change-the-attribute-table-popup-hover-text-in-a-plotly-map%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter