[R] Plotting world maps with locations.

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Sat Feb 13 06:01:17 CET 2021



Sent from my iPhone

> On Feb 12, 2021, at 1:35 PM, Jibrin Alhassan <jibrin.alhassan using unn.edu.ng> wrote:
> 
> Hello Romanus,
> You are to post only the code and the error messages and not all the
> information from your terminal in R session.

That’s not actually the best practice for rhelp questions. More info is better than less. What’s missing, however, is the data. 

— 
David
> 
>> On Fri, Feb 12, 2021, 4:35 PM Romanus Ejike <romanusejike1971 using gmail.com>
>> wrote:
>> 
>> Please, I need help from anyone that can solve this problem.
>> I wanted to plot a world map with locations and names of the locations but
>> could not. The codes I have tried are as shown below.
>> ugwoke using ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>> 
>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu (64-bit)
>> 
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>> 
>>  Natural language support but running in an English locale
>> 
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>> 
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>> 
>>> NMdata <-
>> 
>> read.table("NM1989.txt",col.names=c("SNAME","FNAME","NMTYPE","LAT","LON","ALTI"))
>>> library(ggplot2)
>>> library(sf)
>> Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
>>> library(rnaturalearth)
>>> library(rnaturalearthdata)
>>> world <- ne_countries(scale = "medium", returnclass = "sf")
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,Nmdata$LAT,col = "red",
>> cex = 0.01)
>> Error in xy.coords(x, y) : object 'Nmdata' not found
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>> cex = 0.01)
>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>  plot.new has not been called yet
>> In addition: Warning messages:
>> 1: In xy.coords(x, y) : NAs introduced by coercion
>> 2: In xy.coords(x, y) : NAs introduced by coercion
>> 3: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  locale not supported by Xlib: some X ops will operate in C locale
>> 4: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  X cannot set locale modifiers
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + coord_sf(xlim = c(-180.00, 180.00), ylim = c(-90.00, 90.00), expand =
>> FALSE) + ggtitle("World map") + points(NMdata$LON,NMdata$LAT,col = "red",
>> cex = 0.01, pch = 20)
>> Error in plot.xy(xy.coords(x, y), type = type, ...) :
>>  plot.new has not been called yet
>> In addition: Warning messages:
>> 1: In xy.coords(x, y) : NAs introduced by coercion
>> 2: In xy.coords(x, y) : NAs introduced by coercion.
>> I have also tried the codes below but it did not show the locations.
>> ugwoke using ugwoke-HP-ENVY-Laptop-13-aq0xxx:~/Desktop$ R
>> 
>> R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
>> Copyright (C) 2020 The R Foundation for Statistical Computing
>> Platform: x86_64-pc-linux-gnu (64-bit)
>> 
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>> 
>>  Natural language support but running in an English locale
>> 
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information and
>> 'citation()' on how to cite R or R packages in publications.
>> 
>> Type 'demo()' for some demos, 'help()' for on-line help, or
>> 'help.start()' for an HTML browser interface to help.
>> Type 'q()' to quit R.
>> 
>>> library("ggplot2")
>>> library(sf)
>> Linking to GEOS 3.9.0, GDAL 3.2.0, PROJ 7.2.0
>>> library("rnaturalearth")
>>> library("rnaturalearthdata")
>>> theme_set(theme_bw())
>>> world <- ne_countries(scale = "medium", returnclass = "sf")
>>> class(world)
>> [1] "sf"         "data.frame"
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> +
>> + + ggtitle("World map") + coord_sf(crs = "+proj=laea +lat_0=52 +lon_0=10
>> +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs ")
>> Error in +ggtitle("World map") : invalid argument to unary operator
>>> ggplot(data = world) + geom_sf() + labs( x = "Longitude", y = "Latitude")
>> + ggtitle("World map") + coord_sf(crs = "+proj=laea + lat_0=52 + lon_0=10 +
>> x_0=4321000 + y_0=3210000 + ellps=GRS80 + units=m + no_defs ")
>> Warning messages:
>> 1: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  locale not supported by Xlib: some X ops will operate in C locale
>> 2: In (function (display = "", width, height, pointsize, gamma, bg,  :
>>  X cannot set locale modifiers.
>> I really appreciate any help rendered. Thanks
>> 
>>        [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list