Plotting locations of a state in India in maps using R - r

I have a list of locations from Uttarakhand state in India. The dataset is like this
address lat long
Ajabpur 30.0431765 78.8255226
UHC Ajabpur 30.0431765 78.8255226
Asan Bag 30.5829083 77.7523608
Ashtad 30.6865869 77.8453043
Badripur 30.2843949 78.0656264
Balawala 30.2661801 78.1062092
Ballupur 30.3335862 78.0115041
Barontha 30.066753 79.0192997
I wish to plot these points on the map of Uttarakhand using R. How do i accomplish it?

There are several examples.
but here is one using ggplot2 and ggmap. Look at the manual of ggmap and you will find many options.
data_table <- read.table(text="
add lat long
Ajabpur 30.0431765 78.8255226
UHCAjabpur 30.0431765 78.8255226
AsanBag 30.5829083 77.7523608
Ashtad 30.6865869 77.8453043
Badripur 30.2843949 78.0656264
Balawala 30.2661801 78.1062092
Ballupur 30.3335862 78.0115041
Barontha 30.066753 79.0192997",
header = TRUE)
library(ggplot2)
library(ggmap)
map <- get_map(
location = c(78.825, 30.04),
source = "google", zoom = 15, maptype = "satellite"
)
ggmap(map) +
geom_point(data=data_table, aes(x = long, y = lat), alpha = .5, color="red")

Related

I want to specify the location of a store in Paris using ggmap, but it doesn't come out well

The map doesn't show Paris, shows another country, or shows an error..
register_google key is mine, so I hide it.
library(ggmap)
register_google(key = "...")
dt <- read.csv("sfdff.csv", header=T)
a <- c(mean(dt$lon),mean(dt$lat))
paris <- get_map(a, zoom=7,
scale = 2, size = c(640,640),
maptype="roadmap")
ggmap(paris) +
geom_point(data=dt,
aes(x=lon,y=lat),
size=2, col = "black",
alpha=0.8)
What you could do is using the osmdata package and getbb function to provide a bbox object. In this you don't need a google API key. You can use the following code:
library(ggmap)
pacman::p_load(ggmap, osmdata)
map <- get_map(location = getbb("paris"), source = "stamen")
ggmap(map)
Output:
Now you can add your data points to the ggmap of Paris.

Shared Boundaries too Dark using geom_path()

I'm working on various mapping of data. One of the maps of interest is taking boundary maps and overlaying them on an exist map. These existing maps may come from Google or other sources.
The issue that I'm having is that when I use geom_path(), with an alpha < 1, if two areas share a boundary, that boundary is darker than other boundaries. Any way to make all the boundaries the same transparency?
library(ggplot2)
library(ggmap)
library(maptools)
library(plyr)
zips <- readShapePoly('cb_2016_us_zcta510_500k.shp')
test <- fortify(zips)
zips#data$id <- rownames(zips#data)
zips.points <- fortify(zips)
zips.df <- join(zips.points, zips#data, by = "id")
test_zips <- c(64002,64012,64013,64014,64015,64029,64030,64034,64050
,64051,64052,64053,64054,64055,64056,64057,64063,64064,64065,64070
,64075,64080,64081,64082,64083,64086,64108,64109,64110,64111,64112
,64113,64114,64121,64123,64124,64125,64126,64127,64128,64129,64130
,64131,64132,64133,64134,64136,64137,64138,64139,64141,64145,64146
,64147,64148,64149,64170,64171,64179,64191,64198,64999,66119,66160
,66205,66206,66207,66208,66209,66211,66222,66224,66251)
Valid_Zips <- zips.df[zips.df$GEOID10 %in% test_zips,]
mapImage <- get_map(location = c(lon = -94.4, lat = 38.9),
color = "color",
source = "google",
maptype = "toner-2011",
zoom = 10)
ggmap(mapImage) +
geom_path(aes(x = long, y = lat, group = group)
,color="red",data=Valid_Zips,size=1,alpha = .3)

Improving a location visibility using ggmap function in R

I am marking some points on a UAE map. I am using ggmap and ggplot2 packages for the purpose.
my code for plotting and marking the map is:
library(ggmap)
library(ggplot2)
d <- data.frame(lat=c(24.534505, 24.529291,24.529291, 24.543425, 24.551134, 24.555446, 24.560406, 24.558412, 24.558670, 24.548625, 24.547120, 24.540850, 24.540428, 24.534505),lon=c(55.415467, 55.419130, 55.432415, 55.465657, 55.462406, 55.473639, 55.471087, 55.465286, 55.465211, 55.438385, 55.439173, 55.427146, 55.427119, 55.415467))
map <- get_map("Sweihan, United Arab Emirates", zoom = 11, maptype = "satellite", source = "google")
Sweihan <- ggmap(map)+geom_point(data = d, aes(x = lon, y = lat))+geom_path(data = d, aes(x = lon, y = lat))+scale_x_continuous(limits = c(55.41, 55.48)) +
scale_y_continuous(limits = c(24.52, 24.5655))
Sweihan
Now the thing is after running this code, I am being able to get correct map and exact points that I wanted to plot. But I am not being about to get the clarity of map. I have tried zoom in get_map function, that isn't helping. Is there any approach that I can use within my code to get a visible map.
Any help will be appreciated!
Thanks in Advance!
Finding the map by address is convenient, but there is more control if you use the longitude/latitude
map <- get_map(location = c(mean(d$lon), mean(d$lat)), zoom = 13, maptype = "satellite", source = "google")
ggmap(map)+
geom_point(data = d, aes(x = lon, y = lat))+
geom_path(data = d, aes(x = lon, y = lat))
ggmap has already set the x and y scales, so you will get warnings if you try to replace them.

plotly feature with ggmap

I am plotting all latitude longitude values which I receive on a map like this.
The map has the color as per the time duration of halt recorded at that point.
My agonies are the following:
I cannot zoom in and zoom out - Centering the map is very painful - And I have 10*100 such collections to be plotted and evaluated
I can hardly make out the areas where the halt was specific, all I can see is that it was good with no halt but reality is not that
Hence I looked for plotly and to my surprise they don't have the support.
How can I achieve the results? I don't have a tool like tableau
Please suggest if you can help.
Below code is an example of what I am trying to do with ggmap :
library(ggplot2)
library(data.table)
library(ggmap)
library(maps)
library(mapdata)
lat <- seq(31.26415,31.26831,0.00010)
lon <- seq(76.80890,76.82320,0.00015)
lon <- lon[seq(1,96.2)]
lon <- lon[1:42]
lat_long <- data.frame(lat,lon)
lat_median <- 31.26751
lon_median <- 76.82003
#map <- get_map(location = c(lon_median, lat_median), maptype = "roadmap", zoom = 15)
map <- get_googlemap(center = c(lon_median, lat_median), zoom = 12, maptype = "roadmap",size = c(600, 300), scale = 2)
ggmap(map) +
geom_path(data = lat_long, aes(), size = 2, lineend = "butt") +
geom_point(data = lat_long, color = "red3", size = 1)

How to plot data on a map without using Google map (image)?

I have a csv file with variables name "Latitude","Longitude","PM10 concentration". You can download data here. I want to plot PM10 data on a map of South Korea according to their latitude and Longitude. Also I want to show them as bubble with different size and color.
Following this example I have already plotted PM10 data on Google Map. But now I want do this without using Google map rather by creating spatial object or in any other way.
I tried to write some code but I have download the spatial data for administration area (GADM) of South Korea. But I am not sure that approach is right or wrong.
library(rgdal)
library(ggplot2)
library(maptools)
map<-readOGR('D:/BACKUP/R/GSTAT/R File/shape file korea map',layer ='KOR_adm2')
summary(kmap)
EPSG<-make_EPSG()
EPSG[grepl("WGS 84$", EPSG$note), ]
kmap84<-spTransform(kmap, CRS("+init=epsg:4326"))
kmaps<-fortify(kmap84)
I don't understand what should I do next.
Here's an example:
library(raster)
library(ggplot2)
download.file("https://docs.google.com/uc?id=0ByY3OAw62EShakxJZkplOXZ0RGM&export=download", tf <- tempfile(fileext = ".csv"))
df <- read.csv(tf, row.names = 1)
skorea <- getData("GADM", country = "South Korea", level = 2)
skorea <- fortify(skorea)
ggplot() +
geom_map(data = skorea, map = skorea, aes(x = long, y = lat, map_id = id, group = group),
fill = NA, colour = "black") +
geom_point(data = df, aes(x = LON, y = LAT, size = PM10), colour = "red", alpha = .5) +
scale_size(range = c(1, 5))

Resources