Skip to main content
edited tags
Link
Jan
  • 6.4k
  • 4
  • 15
  • 26
added 102 characters in body
Source Link
vp_050
  • 508
  • 2
  • 5
  • 19

I am using the script below to make to make interactive leaflet map. However, the contours have sharp changes and are not smooth and round. How can I edit this code to achieve that?

The data and code is from this link: https://adelieresources.com/2022/10/making-contour-maps-in-r/

    Sta_den <- eks::st_kde(df) # calculate density
    contours <- eks::st_get_contour(Sta_den, cont=c(20,40,60,80)) %>% 
      mutate(value=as.numeric(levels(contlabel)))
    pal <- colorBin("YlOrRd", contours$contlabel, bins = c(20,40,60,80), reverse = TRUE)
    
    pal_fun <- leaflet::colorQuantile("YlOrRd", NULL, n = 4)
    
    p_popup <- paste("Density", as.numeric(levels(contours$contlabel)), "%")
    
    leaflet::leaflet(contours) %>% 
      leaflet::addTiles() %>% # OpenStreetMap by default
      leaflet::addPolygons(fillColor = ~pal_fun(as.numeric(contlabel)),
                           popup = p_popup, weight=2)%>% 
      leaflet::addLegend(pal = pal, values = ~contlabel, group = "circles", position = "bottomleft",title="Density quantile")

I am using the script below to make to make interactive leaflet map. However, the contours have sharp changes and are not smooth and round. How can I edit this code to achieve that?

    Sta_den <- eks::st_kde(df) # calculate density
    contours <- eks::st_get_contour(Sta_den, cont=c(20,40,60,80)) %>% 
      mutate(value=as.numeric(levels(contlabel)))
    pal <- colorBin("YlOrRd", contours$contlabel, bins = c(20,40,60,80), reverse = TRUE)
    
    pal_fun <- leaflet::colorQuantile("YlOrRd", NULL, n = 4)
    
    p_popup <- paste("Density", as.numeric(levels(contours$contlabel)), "%")
    
    leaflet::leaflet(contours) %>% 
      leaflet::addTiles() %>% # OpenStreetMap by default
      leaflet::addPolygons(fillColor = ~pal_fun(as.numeric(contlabel)),
                           popup = p_popup, weight=2)%>% 
      leaflet::addLegend(pal = pal, values = ~contlabel, group = "circles", position = "bottomleft",title="Density quantile")

I am using the script below to make to make interactive leaflet map. However, the contours have sharp changes and are not smooth and round. How can I edit this code to achieve that?

The data and code is from this link: https://adelieresources.com/2022/10/making-contour-maps-in-r/

    Sta_den <- eks::st_kde(df) # calculate density
    contours <- eks::st_get_contour(Sta_den, cont=c(20,40,60,80)) %>% 
      mutate(value=as.numeric(levels(contlabel)))
    pal <- colorBin("YlOrRd", contours$contlabel, bins = c(20,40,60,80), reverse = TRUE)
    
    pal_fun <- leaflet::colorQuantile("YlOrRd", NULL, n = 4)
    
    p_popup <- paste("Density", as.numeric(levels(contours$contlabel)), "%")
    
    leaflet::leaflet(contours) %>% 
      leaflet::addTiles() %>% # OpenStreetMap by default
      leaflet::addPolygons(fillColor = ~pal_fun(as.numeric(contlabel)),
                           popup = p_popup, weight=2)%>% 
      leaflet::addLegend(pal = pal, values = ~contlabel, group = "circles", position = "bottomleft",title="Density quantile")
Source Link
vp_050
  • 508
  • 2
  • 5
  • 19

Make smooth contours in when using leaflet and tmaps in R

I am using the script below to make to make interactive leaflet map. However, the contours have sharp changes and are not smooth and round. How can I edit this code to achieve that?

    Sta_den <- eks::st_kde(df) # calculate density
    contours <- eks::st_get_contour(Sta_den, cont=c(20,40,60,80)) %>% 
      mutate(value=as.numeric(levels(contlabel)))
    pal <- colorBin("YlOrRd", contours$contlabel, bins = c(20,40,60,80), reverse = TRUE)
    
    pal_fun <- leaflet::colorQuantile("YlOrRd", NULL, n = 4)
    
    p_popup <- paste("Density", as.numeric(levels(contours$contlabel)), "%")
    
    leaflet::leaflet(contours) %>% 
      leaflet::addTiles() %>% # OpenStreetMap by default
      leaflet::addPolygons(fillColor = ~pal_fun(as.numeric(contlabel)),
                           popup = p_popup, weight=2)%>% 
      leaflet::addLegend(pal = pal, values = ~contlabel, group = "circles", position = "bottomleft",title="Density quantile")