ggmap

Add legend to ggmap

南笙酒味 提交于 2019-12-11 18:07:17
问题 I am trying to add a legend to a plot generated by ggmap package in R. The dataset I am working with is Latitude Longitude amount 61.37072 -152.40442 436774 32.80667 -86.79113 3921030 34.96970 -92.37312 1115087 33.72976 -111.43122 5068957 The code I am using is library(ggplot2) library(ggmap) MyMap <- get_map(location = c(lon = -96.5, lat = 40.68925), zoom = 4,maptype = "terrain", scale = 2) ggmap(MyMap)+ geom_point(data = data,aes(x = Longitude , y = Latitude ),size=sqrt(data$amount)/800,col

R 3.2.1, reverse colors on map

China☆狼群 提交于 2019-12-11 10:03:29
问题 Here is part of R code # create a new grouping variable Percent_SEP12_Assets <- ifelse(sep[,8] <= 33, "Lower Third", ifelse(sep[,8] >= 55, "Upper Third", "Middle Third")) # get the map bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 0.3) map <- get_map(bbox) # plot the map and use the grouping variable for the fill inside the aes ggmap(map) + geom_point(data=sep, aes(x = Longitude, y = Latitude, color=Percent_SEP12_Assets ), size=5, alpha=0.6) + scale_color_manual(breaks=c("Upper Third",

Plotting points on a map with size depending on category count

僤鯓⒐⒋嵵緔 提交于 2019-12-11 09:56:04
问题 I have a dataset with animal trappings, where in each location I have multiple animals of several different species captured. I would like to plot this information on a map, such that each point would represent location of trapping of a given species and the size of each point would represent a number of animals of this species trapped in this location. I can do all this except the last point, differentiating point size depending on the counts in each category and location. Data: > test

R shiny. Error pops up while using ggmap

对着背影说爱祢 提交于 2019-12-11 09:37:41
问题 I have a dataset with latitude and longitude place latitude longitude w 28.844692 77.103305 x 28.750925 77.1963099 y 28.702134 77.2202666 z 28.716547 77.1704 I've tried the code below and it is working fine: a <- coordinates[coordinates$place=="y",c("place","latitude","longitude")] get_constituency <- get_map(c(a$longitude, a$latitude)) ggmap(get_constituency) + geom_point(aes(x = a$longitude, y = a$latitude, size=10), alpha = .5, col="red") + scale_size(range=c(3,5)) I am using shiny to

Dynamic plotting using ggmap package in R

自古美人都是妖i 提交于 2019-12-11 06:58:50
问题 I am trying to plot my points over the google maps. However, the problem I am facing is I have to set the location points and zoom for every input data file. I tried to use it via variables but its not working. Can anyone help? Here what I tried: library(ggmap) library(ggplot2) lionmap <- get_map(location=c(70.76, 21.038), zoom=12, maptype="hybrid") This code only works for static points. How can I make it dynamic? Here's the head structure for my dataset: lion.id date time activity lat long

How to create unique labels for multiple rows in geom_text?

心不动则不痛 提交于 2019-12-11 06:43:40
问题 I have a data frame like this zip state users longitude latitude 00501 NY 1000 -72.63708 40.92233 00544 NY 1000 -72.63708 40.92233 00601 PR 2000 -66.74947 18.1801 00602 PR 2000 -67.18024 18.36329 I'm plotting number of users using ggmap and geom_point. map<-get_map(location='united states', zoom=4, maptype = "terrain", source='google',color='color') ggmap(map) + geom_point( aes(x=longitude, y=latitude, show_guide = TRUE, colour=users), data=data, alpha=.5, na.rm = T) + scale_color_gradient

Cannot run map_data(“state”)

こ雲淡風輕ζ 提交于 2019-12-11 05:55:57
问题 I am trying to work on a US map in R. I have done it a lot of times but this time it gives me this error when I try to load: us<- map_data("state") Error in .C(C_map_type, as.character(mapbase), integer(1)) : Incorrect number of arguments (2), expecting 0 for '' I have ggmap and ggplot2 libraries loaded. Where am I going wrong? 回答1: You need the 'maps' package along with ggmap. library(maps) library(ggmap) us<- map_data("state") This should work 回答2: It looks like there are bugs in tidyverse

reverse geocoding to extract address components

女生的网名这么多〃 提交于 2019-12-11 05:26:32
问题 I'm trying to reverse geocode with R. I first used ggmap but couldn't get it to work with my API key. Now i'm trying it with googleway. newframe[,c("Front.lat","Front.long")] Front.lat Front.long 1 -37.82681 144.9592 2 -37.82681 145.9592 newframe$address <- apply(newframe, 1, function(x){ google_reverse_geocode(location = as.numeric(c(x["Front.lat"], x["Front.long"])), key = "xxxx") }) This extracts the variables as a list but I can't figure out the structure. I'm struggling to figure out how

Custom map style with ggmap

一世执手 提交于 2019-12-11 04:54:47
问题 I have customized a style for use with ggmap using https://mapstyle.withgoogle.com/. My question is how to integrate the JSON into my R code. I tried the following code to no avail: map <- get_googlemap(center = 'London', zoom = 15, style = c('element:labels|visibility:off', 'feature:road.local|visibility:off')) ggmap(map) It works with either of the style commands alone but not together. Where is the bug in my code? 回答1: I have developed a package ggmapstyles , which should help with this

Is ggmap broken? Basic qmap() produces “arguments imply differing number of rows: 0,1”

久未见 提交于 2019-12-11 04:13:17
问题 I've used ggmap many times in the past to produce maps with a particular coordinate as the focal point. It has generally been as simple as defining the focal point via the location= argument in qmap() , and adding on geoms to the map as needed. Today, I opened ggmap for the first time in a while, and it simply is not successful in performing the most basic of mapping tasks. devtools::install_github("dkahle/ggmap") #Making sure I'm up-to-date library(ggmap) qmap(location = "White House", zoom