Coodinates Not Plotting on Map

Hi all, I am fairly new to R and am trying to make a basic map of Portugal with some coodinates of nest sites plotted on it. However, my coordinates are not showing up and I am very confused as to why!

Below is my code that I have used, and I have included a screenshot of the map it produces- it makes a map but just a blank one!

Any suggestions very welcome!

good_map<-ggplot(data=world)+geom_sf(color='black',fill='darkolivegreen1')+
  xlab('Longitude')+ylab('Latitude')+ggtitle('South Portugal',subtitle = ('Stork Nests 2019'))+
  coord_sf(xlim = c(-10.167179, -7.355167), ylim = c(36.897690, 39.004960), expand = FALSE)

good_map

stork_nest_map<-good_map +
  geom_point(data=X2019_Average_Data_Ready,aes(x=Longitude,y=Latitude,fill='No. of Nests'),shape=21,size=2,color="black")

stork_nest_map

Can show us the contents of the first two observations of X2019....
To protect the privacy of the subjects you could just change the coordinates a little...

Example_Of_Data

Many thanks for your reply, please see this sample ^^

Not sure what went wrong at your side.
It could be the name of the variable 'Number of Nests'.
Anyway for me this works:

library(ggplot2)

library("rnaturalearth")
library("rnaturalearthdata")
library("rgeos")
#> Loading required package: sp
#> rgeos version: 0.5-3, (SVN revision 634)
#>  GEOS runtime version: 3.8.0-CAPI-1.13.1 
#>  Linking to sp version: 1.4-1 
#>  Polygon checking: TRUE

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

X2019_Average_Data_Ready <-
  data.frame(
    Colony = c('a','b','c'),
    `No. of Nests` = c(3,1,12),
    Latitude = c(37.8802,37.4674,37.7297),
    Longitude= c(-7.9577,-8.98582,-8.75367),
    `Av.No. of Fledglings`=c(1,2,1.25),
    stringsAsFactors = F
  )

good_map<-ggplot(data=world) +
  geom_sf(color='black',fill='darkolivegreen1') +
  xlab('Longitude') + 
  ylab('Latitude') + 
  ggtitle('South Portugal', 
          subtitle = ('Stork Nests 2019')) +
  coord_sf(xlim = c(-10.167179, -7.355167), ylim = c(36.897690, 39.004960), expand = FALSE)

good_map


stork_nest_map<-good_map +
  geom_point(data=X2019_Average_Data_Ready,
             aes(x=Longitude,y=Latitude,fill=`No..of.Nests`),
             shape=21,size=2,color="black")

stork_nest_map

Created on 2020-05-23 by the reprex package (v0.3.0)

Wow you've got it working - that's fantastic!

I will try changing the name of my variable "No. of nests" to a name that does not contain any spaces and see if that helps. Perhaps just Nests.

One thing I notice is that you manually wrote down all of the latitudes, longitudes and number of nests in your code. Is it compulsory to do it in that way? My data set isn't huge, maybe 40 records or so but it could definitely be a bit tedious and attract mistakes.

Also, thank you so much for taking the time to help me troubleshoot - it is very much appreciated!

Edit: After trying to change the name to just Nests it comes up with the error - cannot find the color 'Nests'

A name is just a name, but be aware of names with spaces in it.
I saw your 'Edit' where you said to have an error with 'Nests'.
To show it works see below (I removed the two output plots).
It should also be working for you: did you change your X2019_Average_Data_Ready file and did you save it?

The reason that I wrote out manually all the data is that did not have your data set and needed some input to test the code. You had the colony information already available in a data set, so no need for you to type it over.

When I tried to find a source for your world map I found with google the webpage Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 1: Basics . Maybe also interesting for you.

library(ggplot2)

library("rnaturalearth")
library("rnaturalearthdata")
library("rgeos")
#> Loading required package: sp
#> rgeos version: 0.5-3, (SVN revision 634)
#>  GEOS runtime version: 3.8.0-CAPI-1.13.1 
#>  Linking to sp version: 1.4-1 
#>  Polygon checking: TRUE

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

X2019_Average_Data_Ready <-
  data.frame(
    Colony = c('a','b','c'),
    Nests  = c(3,1,12),
    Latitude = c(37.8802,37.4674,37.7297),
    Longitude= c(-7.9577,-8.98582,-8.75367),
    `Av.No. of Fledglings`=c(1,2,1.25),
    stringsAsFactors = F
  )

good_map<-ggplot(data=world) +
  geom_sf(color='black',fill='darkolivegreen1') +
  xlab('Longitude') + 
  ylab('Latitude') + 
  ggtitle('South Portugal', 
          subtitle = ('Stork Nests 2019')) +
  coord_sf(xlim = c(-10.167179, -7.355167), ylim = c(36.897690, 39.004960), expand = FALSE)

good_map

Removed the map but is was shown okay (without the points of course)


stork_nest_map<-good_map +
  geom_point(data=X2019_Average_Data_Ready,
             aes(x=Longitude,y=Latitude,fill=Nests),
             shape=21,size=2,color="black")

stork_nest_map

Removed the map but is was shown okay (now with the points)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.