Skip to content
Related Articles

Related Articles

Improve Article

Adding Data Points to world map in R

  • Last Updated : 04 Jul, 2021

In this article, we are going to see how to add DataPoint to the world map in R Programming Language. The world map in R can be plotted on a graphical device using various external packages in R Programming. The points can be marked and data can be annotated in these plots using various methods. 

Dataset Used: worldcities.csv


# Read dataset and convert it into
# Dataframe
data <- read.csv("worldcities.csv")
df <- data.frame(data)


Method 1: Using maps package

Maps: The “maps” package in R is used to draw and display geographical maps. It contains various databases for denoting countries, continents and seas. The package can be installed and loaded into the working space using the following command : 


The package contains the ‘world’ database, which contains descriptive images of continents and it no longer contains lakes and lake islands. The map function of this package is used to draw lines and polygons as specified by a map database, which incorporates the geographical map. 

map(database = “world”)

The data can be specified in the form of latitudes and longitudes and the names of the cities. The point can then be annotated over this plot using the plot() method. It can be customized with various attributes to improve readability and enhance the graphics. 

Note: We will plot first 500 cities


# Load the required libraries
map(database = "world")
# marking points on map
points(x = df$lat[1:500], y = df$lng[1:500], col = "Red")


Method 2: Using ggplot2 and map

Here we are going to use ggplot2() and map, map_data() function returns the dataset of the country along with longitude and latitude.


usa <- map_data("usa")


Now we plot a world map along with datapoints:


df = head(usa)
# marking points on map
text(x = df$long, y = df$lat, col = "Red")


My Personal Notes arrow_drop_up
Recommended Articles
Page :