plotly feature with ggmap - r

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)

Related

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)

ggmap renders blank map

I am trying to plot few points on map. But I get a blank map with just the points marked in red. The map is missing
Below code is reporducible
library(maps)
library(mapdata)
library(ggplot2)
library(ggmap)
lon <- c(-122.1817252,-119.4179324,-95.7128910,-71.0588801,-81.0348144)
lat <- c(37.452960,36.778261,37.090240,42.360082,34.000710)
all_places_geocoded <- data.frame(lon,lat)
gc <- geocode('australia')
center <- as.numeric(gc)
map <- get_googlemap(location = center,maptype = "roadmap", zoom=1)
ggmap(map) +
geom_point(data = all_places_geocoded, color = "red3", size = 1)

Resize output window of ggmap

I am plotting few lat longs using ggmap and I get the output like this
I use the following code to generate this output, below code is part of the o/p
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)
ggmap(map) +
geom_path(data = lat_long, aes(), size = 2, lineend = "butt") +
geom_point(data = lat_long, color = "red3", size = 1)
My output window has lot of white space, which I could have used to show in the map. Can I increase this map output to better fit the window?
If you use the get_googlemap function you can specify the dimensions and it doesn't have to be square e.g.:
map <- get_googlemap('paris', zoom = 15, size = c(500, 200), scale = 2)

Plotting locations of a state in India in maps using 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")

Overlaying points on a ggmap

So I'm putting trees in forest plots into a map of Madagascar
The beginning on the data set looks like this:
#ggmap!
library(ggmap)
library(mapproj)
map <- get_map(location = 'Madagascar', zoom = 4)
ggmap(map)
map <- get_map(location = 'Madagascar', zoom = 10)
geocode("kianjavato")
#lon lat
#47.86682 -21.38024
k <- "kianjavato"
#qmap(k, zoom = 16)
#qmap(k, zoom = 16, source = "stamen", maptype = "toner")
myMap <- get_map(location=k, source="stamen", maptype="toner", crop=FALSE, zoom=16)
# having trouble zooming
ggmap(myMap)
Here is the code I use to make the map and get the points:
ggplot(data=GPScorrect,aes(x=Lon,y=Lat))+geom_point()
But when I go to plot the two together using this code:
ggmap(myMap) + geom_point(data=GPScorrect,aes(x = 'Lon', y ='Lat'))
I get this error message:
Error: Discrete value supplied to continuous scale
PLEASE HELP
When asking questions, be sure to provide a working example that executes front to back until it encounters the error you're asking about. In this case, you don't supply data for GPScorrect.
Un-quote your aesthetic mappings. If you re-work the following stripped down example you should get what you're looking for:
library(ggmap)
library(mapproj)
myMap <- get_map(location = 'Madagascar', zoom = 6)
e1 <- geocode('Antananarivo')
e2 <- geocode('Toamasina')
e3 <- geocode('Antsirabe')
GPScorrect <- rbind(e1, e2, e3)
ggmap(myMap) + geom_point(data=GPScorrect,aes(x = lon, y =lat), color = 'firebrick', size = 3)

Resources