Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

projection CRS polygon #864

Open
antoine4ucsd opened this issue May 26, 2023 · 0 comments
Open

projection CRS polygon #864

antoine4ucsd opened this issue May 26, 2023 · 0 comments

Comments

@antoine4ucsd
Copy link

Hello
I am trying to plot country data on a worldma but I am having issues with countries that are 'shrink' on one side.
I tried to change projection but I was not successful so far...

but when I add polygon

leaf_map_tiles =leaflet::leaflet(world_map,
                           options = leaflet::leafletOptions(
                                                                minZoom = 1.3,center = c(28,13), 
                                                             maxZoom = 4,
                                                             zoom=1.3))

 leaf_map_tiles%>%
        leaflet::addPolygons(stroke = T, 
                             smoothFactor = 0.3,
                             weight = 1,
                            fillOpacity = ~factop(myvar),
                             fillColor = ~pal2(myvar),
                             color = "white")

then it shows up like below:

example1

I assumed it could be a projection issue but none of my attempt were succesfull

world_map
class       : SpatialPolygonsDataFrame 
features    : 241 
extent      : -180, 180, -89.99893, 83.59961  (xmin, xmax, ymin, ymax)
crs         : +proj=longlat +datum=WGS84 +no_defs 

so I tried equal earth projection

world_map <- spTransform(world_map, CRS("+proj=eqearth +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"))
world_map_sf <- st_as_sf(world_map)
mycrs <- leafletCRS(proj4def = "+proj=eqearth  +lon_0=0  +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84")

leaflet(world_map_sf, options = leafletOptions(crs = mycrs)) %>%
        addPolygons(weight = 1, color = "#444444", opacity = 1,
                    fillColor = ~pal_equalearth(num_site2), fillOpacity = 0.7, smoothFactor = 0.5,
                    label = ~paste(name, num_site2),
                    labelOptions = labelOptions(direction = "auto"))

but the map is not showing up anymore
all ideas are welcome!

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant