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--
  • 20,766
  • 7
  • 52
  • 87
  • 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

1 Answers1

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--
  • 20,766
  • 7
  • 52
  • 87
  • 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