df<-read.csv("https://raw.githubusercontent.com/tuyenhavan/Statistics/Dataset/My_data.csv",sep=",")
head(df)
## FID Field1 lat lon ser
## 1 0 1 -37.74922 175.6729 T
## 2 1 2 -43.26288 170.3655 H
## 3 2 3 -37.67690 175.4695 P
## 4 3 4 -37.27856 175.4390 B
## 5 4 5 -37.25098 175.5982 C
## 6 5 6 -37.64233 175.3597 T
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.2.5
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.2.5
library(ggplot2)
library(RgoogleMaps)
## Warning: package 'RgoogleMaps' was built under R version 3.2.5
library(sp)
## Warning: package 'sp' was built under R version 3.2.5
# Create a spatial point data frame from ` a data frame`
coordinates(df)<-~lon+lat
proj4string(df)<- CRS("+proj=longlat +datum=WGS84")
# amke plot larger
par(mar=rep(2,4))
plot(df)

# Combine online maps with spatial point data frame
points<-data.frame(df)
nz<-get_map(location = "NZ",zoom = 5, maptype = "terrain")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=NZ&zoom=5&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=NZ&sensor=false
ggmap(nz, base_layer = ggplot(data=points)) + geom_point(aes(x=lon,y=lat,color=ser)) + facet_grid(~ser) + ggtitle("Distribution of Ser") + xlab("Longitute") + ylab("Latitude") + theme(plot.title = element_text(hjust=0.5))
