[R-sig-Geo] question on the use of Leaflet for plotting points and rater GeoTIFF

Ben Tupper btupper @end|ng |rom b|ge|ow@org
Fri Aug 13 14:00:27 CEST 2021


Hi,

I don't think we can run the code since it isn't reproducible (see
https://CRAN.R-project.org/package=reprex
<https://cran.r-project.org/package=reprex> for help with that.)  But here
are some hints:

flipped color bar - I love to use RSeek.org which is an R-centric search
engine -  you may want to bookmark it or add it to your search engine list
if your browser supports that. https://rseek.org/?q=leaflet+flip+color+bar
This search hits a number of discussions on flipping the color bar.

color intensity - oooooh, there is so much discussion in the world about
colors.  By default raster images have opacity of 1 (fully opaque) when
rendered in leaflet, so really it is a matter of finding the color table
you want and then applying colorNumeric judiciously.  For me it comes down
to trial and error.  If you are looking for eye pop! then perhaps check out
the viridis options.  See ?colorNumeric

Cheers,
Ben

On Thu, Aug 12, 2021 at 2:24 PM Gabriel Cotlier <gabiklm01 using gmail.com> wrote:

> Dear Ben,
>
> Thanks a lot for your help!
> Actually it worked very well for me with the link you gave me.
> However, for some reason the numbers of the values in color scale goes
> from the lower values set at the top  (blue) of the sacale to the
> higher values set at the bottom (red ) and it would be better for me if it
> goes from from the lower values in the bottom (blue) to higher value in the
> top (red), since is temperature going from the lower to the higher.
>  Another issue I found a bit problematic for me to modify is that the
> color palette is too "light", for instance not like the color palette "Jet"
> in Matlab or Python, it seems as if the intensity of the colors of the
> temperature colors is low or light maybe is a transparency and should
> change opacity ....?
>
> Maybe you or somebody knows a possible way to improve these two issues a
> bit ?
>
> Here is the code :
>
> # color palettes
> # pal <- colorNumeric(palette = "Spectral", values(raster), na.color =
> "transparent" , reverse = TRUE)
> pal <- colorNumeric(palette = "RdYlBu", values(raster), na.color =
> "transparent" , reverse = TRUE)
>
> # plot map
> leaflet() %>%
>   addTiles(urlTemplate = "
> https://mts1.google.com/vt/lyrs=s&hl=en&src=app&x={x}&y={y}&z={z}&s=G",
> attribution = 'Google')  %>%
>   addPolygons(data = polygon,weight=5,col = 'black')  %>%
>   addCircles(data = points, color = "White", radius = 500, fillOpacity =
> 1,opacity = 9)%>%
>   addRasterImage(raster, project = FALSE, colors = pal) %>%
>   addLegend(pal = pal, values = values(raster), title = "Temperature",
> opacity = 9)  # ,labFormat = labelFormat(transform = function(x) sort(x,
> decreasing = TRUE)))
>
> Thanks a lot again for your help.
> Kind regards,
> Gabriel
>
>
> On Thu, Aug 12, 2021 at 5:07 PM Ben Tupper <btupper using bigelow.org> wrote:
>
>> Hi,
>>
>> See the "markers" and "raster images" sections here
>> http://rstudio.github.io/leaflet/markers.html
>>
>> Cheers,
>> Ben
>>
>> On Thu, Aug 12, 2021 at 5:02 AM Gabriel Cotlier <gabiklm01 using gmail.com>
>> wrote:
>>
>>> Hello.
>>>
>>> I would like to use Leaflet package to plot over a Google Satellite base
>>> map :
>>>
>>> 1.  a shapefile of polygon
>>> 2.  a shapefile of points
>>> 3,  a GeoTIFF image
>>>
>>> I could use the Leaflet package to get plotted successfully only the
>>> first
>>> Item of the list above with the following code :
>>>
>>> require(rgdal)
>>> library(rgeos)
>>> library(raster)
>>>
>>> shapeData <- raster::shapefile('Seattle_boundries.shp')
>>> shapeData <- spTransform(shapeData, CRS("+proj=longlat +ellps=GRS80"))
>>>
>>> leaflet() %>%
>>>   addTiles(urlTemplate = "
>>> https://mts1.google.com/vt/lyrs=s&hl=en&src=app&x={x}&y={y}&z={z}&s=G",
>>> attribution = 'Google')  %>%
>>>   addPolygons(data=shapeData,weight=5,col = 'red')
>>>
>>> How is it possible to find a way to complete the code above for plotting
>>> the item 2 and 3 as well in the same Leaflet figure.
>>>
>>> Is there any possible solution that can enable this task?
>>>
>>> Thanks for your help.
>>>
>>> Kind regards
>>> Gabriel
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo using r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>> --
>> Ben Tupper (he/him)
>> Bigelow Laboratory for Ocean Science
>> East Boothbay, Maine
>> http://www.bigelow.org/
>> https://eco.bigelow.org
>>
>>

-- 
Ben Tupper (he/him)
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list