Search code examples
rggmap

Removed rows containing missing values ggmap


So I'm trying to make a 2d latitude-longitude map with the package ggmap and I'm encountering a problem:

dataset:

slddataset
    # A tibble: 382 x 17
   station  year    jd sl_pa   sst   sss   ssf depth   sbt   sbs   sbf gravel sand   silt   clay   lat  long
     <int> <int> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>  <dbl> <dbl> <dbl>
 1    4101  2014   142     0 11.7   25.0 0.419  39.9  4.95  31.9 0.320  2.36   97.5 0.110  0.0300  42.2  70.3
 2    4102  2014   142     0 11.3   37.8 0.509  27.6  5.03  31.9 0.372  0.390  99.5 0.0700 0.0200  42.2  70.3
 3    4104  2014   142     0 11.3   41.2 0.803  24.9  5.50  31.7 0.556  0.700  99.2 0.0800 0.0700  42.2  70.3
 4    4105  2014   142     0 10.6   30.8 0.808  28.3  5.14  31.9 0.596  6.83   93.1 0.0700 0.0300  42.2  70.2
 5    4106  2014   142     0 10.5   30.7 0.693  35.6  4.93  32.1 0.887 10.8    89.1 0.0500 0.0700  42.2  70.2
 6    4107  2014   142     0 11.0   30.7 0.724  41.3  4.44  32.3 0.684 11.3    88.5 0.110  0.120   42.2  70.2
 7    4108  2014   142     0 10.3   30.8 0.741  44.4  4.28  32.5 0.340  4.77   95.0 0.110  0.100   42.2  70.1
 8    4109  2014   142     0  9.97  30.9 0.980  44.3  4.32  32.4 0.398  7.80   92.0 0.110  0.110   42.2  70.1
 9    4110  2014   142     0 10.9   30.7 0.794  41.2  4.60  32.3 0.592 10.3    89.5 0.100  0.0900  42.2  70.2
10    4113  2014   143     0 12.0   30.5 0.684  32.2  4.98  31.9 0.336  0.320  99.6 0.0600 0.0300  42.2  70.3
    # ... with 372 more rows

error:

library(ggmap)

stellwagen<-ggmap(get_googlemap(center="stellwagen bank",zoom=7,maptype = "satellite"))

enter image description here

stellwagen + geom_point(aes(x=long, y=lat, color=sl_pa),data=slddataset)

Warning message: Removed 382 rows containing missing values (geom_point).

Anyone have any ideas?


Solution

  • I think your longitudes are wrong in slddataset. They should all be negative. After correcting those, I can plot the points on the map.

    library(dplyr)
    library(ggmap)
    
    slddataset <- slddataset %>% mutate(long = long * -1)
    
    stellwagen<-ggmap(get_googlemap(center="stellwagen bank",zoom=7,maptype = "satellite"))
    
    stellwagen + 
      geom_point(aes(x=long, y=lat),data=slddataset) 
    

    enter image description here

    DATA

    slddataset <- read.table(text = "station  year    jd sl_pa   sst   sss   ssf depth   sbt   sbs   sbf gravel sand   silt   clay   lat  long
                             1    4101  2014   142     0 11.7   25.0 0.419  39.9  4.95  31.9 0.320  2.36   97.5 0.110  0.0300  42.2  70.3
                             2    4102  2014   142     0 11.3   37.8 0.509  27.6  5.03  31.9 0.372  0.390  99.5 0.0700 0.0200  42.2  70.3
                             3    4104  2014   142     0 11.3   41.2 0.803  24.9  5.50  31.7 0.556  0.700  99.2 0.0800 0.0700  42.2  70.3
                             4    4105  2014   142     0 10.6   30.8 0.808  28.3  5.14  31.9 0.596  6.83   93.1 0.0700 0.0300  42.2  70.2
                             5    4106  2014   142     0 10.5   30.7 0.693  35.6  4.93  32.1 0.887 10.8    89.1 0.0500 0.0700  42.2  70.2
                             6    4107  2014   142     0 11.0   30.7 0.724  41.3  4.44  32.3 0.684 11.3    88.5 0.110  0.120   42.2  70.2
                             7    4108  2014   142     0 10.3   30.8 0.741  44.4  4.28  32.5 0.340  4.77   95.0 0.110  0.100   42.2  70.1
                             8    4109  2014   142     0  9.97  30.9 0.980  44.3  4.32  32.4 0.398  7.80   92.0 0.110  0.110   42.2  70.1
                             9    4110  2014   142     0 10.9   30.7 0.794  41.2  4.60  32.3 0.592 10.3    89.5 0.100  0.0900  42.2  70.2
                             10    4113  2014   143     0 12.0   30.5 0.684  32.2  4.98  31.9 0.336  0.320  99.6 0.0600 0.0300  42.2  70.3",
                             header = TRUE, stringsAsFactors = FALSE)