Reputation: 841
I'm trying to map location data on map by using ggmap. The points are defined by latitudes and longitude, and are spreaded out on a wide range of longitude. However, ggmap only allows for a square box.
You can download the location data here: https://www.dropbox.com/s/2s33ccpu4m3vsl9/data.csv?dl=0
The code I used to generate the map is as follow:
geoCodes <- geocode("Kazan, Russia")
map = get_googlemap(
center=c(geoCodes$lon,geoCodes$lat), #Long/lat of centre
zoom=3,
maptype='roadmap', #also hybrid/terrain/roadmap
scale = 2)
data = data.frame (testTrain$lon_1, testTrain$lat_1,testTrain$isDuplicate)
ggmap(map, extent='normal', size = c(900, 900)) + geom_point (data = data,
aes (
x = testTrain$lon_1,
y = testTrain$lat_1,
fill = factor (testTrain$isDuplicate)
),
pch = 21,
colour = "white",
size = 2,
alpha = 0.4
) +
scale_fill_brewer (palette = "Set1", name = "Duplicates") +
theme (
legend.position = c(0.05, 0.05), # put the legend INSIDE the plot area
legend.justification = c(0, 0),
legend.background = element_rect(colour = F, fill = "white"),
legend.key = element_rect (fill = F, colour = F),
panel.grid.major = element_blank (), # remove major grid
panel.grid.minor = element_blank (), # remove minor grid
axis.text = element_blank (),
axis.title = element_blank (),
axis.ticks = element_blank ()
)
Is there a way to expand the range of ggmap so it covers a wider area?
Upvotes: 1
Views: 997
Reputation: 3914
scale_y_continuous()
option would allow you to trim the graph to make it appear rectangular
ggmap( get_googlemap(
center = c(lon = 37.6173, lat = 55.7558), #Long/lat of centre
zoom=3,
size=c(600,600),
maptype='roadmap', #also hybrid/terrain/roadmap
scale = 2)
)+ scale_y_continuous(limits=c(30, 60))
Upvotes: 1