2

I need to make a map where the interpolated data is on it. My code for plotting is:

library(ggplot2)
theme_set(theme_bw())
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggthemes)
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
ggplot(data = world)+
  geom_tile(data = d, aes(x = lon, y = lat, fill=x))+
  geom_raster(data = d, aes(x = lon, y = lat, fill=x))+
  geom_sf()+
  coord_sf(xlim=c(3,35), ylim=c(52,72))

I have received a plot like this

enter image description here

But I need only the countries contour to be on the plot with no difference either it is land or sea. Could ypu please help me in terms of this boarders.

M--
  • 25,431
  • 8
  • 61
  • 93
  • You should provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) What is `d`? – M-- Dec 16 '19 at 23:22

2 Answers2

1

You may use the function ne_coastline() if you are interested in plotting the coastlines only.

library("ggplot2")
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")

world <- ne_coastline(scale = "medium", returnclass = "sf")

ggplot(world) +
  geom_sf() +
  coord_sf(xlim = c(3, 35), ylim = c(52, 72)) +
  theme_void()

enter image description here

P. Denelle
  • 790
  • 10
  • 24
0

You can set the set the alpha for fill in your geom_sf, so it won't be visible. Look below;

library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggthemes)
library(rgeos)

world <- ne_countries(scale = "medium", returnclass = "sf")

ggplot() +
  geom_tile(data = d, aes(x = lon, y = lat, fill=x)) +
  geom_raster(data = d, aes(x = lon, y = lat, fill=x)) +
  geom_sf(data = world, fill=alpha("lightgrey", 0), color="lightgrey") +
  coord_sf(xlim=c(3,35), ylim=c(52,72)) + 
  theme_bw()

Here's an example only showing the world map.

ggplot() +
  geom_sf(data = world, fill=alpha("lightgrey", 0), color="lightgrey") +
  coord_sf(xlim=c(3,35), ylim=c(52,72)) + 
  theme_bw()

M--
  • 25,431
  • 8
  • 61
  • 93
  • It sounds like they only want a coastline to be drawn (I think). So that'd be no `fill`, but also no internal land borders. – Axeman Dec 17 '19 at 00:15
  • @Axeman I though they don't want the borders at first. But it's the other way around. Using `alpha` should do the trick. – M-- Dec 17 '19 at 01:35