Shapefile and Raster
Overview
Teaching: 10 min
Exercises: 0 minQuestions
Objectives
Plot Shapefile for geography study
Download shape file data [here](https://opendata.arcgis.com/datasets/a21fdb46d23e4ef896f31475217cbb08_1.zip)
Store it in your folder: c:/R/GIS/ in Windows or /user/R/GIS in MacOS
Unzip it and rename all files to `Countries_WGS84.*` under `C:/GIS/`
Install additional packages:
install.packages("rgdal")
install.packages("colorspace")
Perform plotting
library(rgdal)
library(colorspace)
library(maps)
setwd('c:/R/GIS/')
gfile <- readOGR(dsn="Countries_WGS84.shp")
names(gfile)
gfile$CNTRY_NAME
plot(gfile)
plot(gfile,col=rainbow_hcl(50))
llgridlines(gfile,lty=5)

Plot raster
Here we will plot a raster data base using Global land cover data set. The data can be downloaded from here. Unzip and put the raster data to working directory:
install.packages("raster")
library(raster)
library(rgdal)
setwd('c:/R/GIS/')
#import raster
Gcover <- raster("GLOBCOVER_L4_200901_200912_V2.3.tif")
#plot raster
plot(Gcover,main="GLobal Land cover")

Key Points
Shapefile
Raster