How to join ggplot (with lon, lat and padding value) using ggmap?

I want to have a map representing the distribution of values ​​over an area with some scale. Here is my data frame:

head(trip)
   TIP      LON     LAT
1 1.318878 -73.9932 40.7223
2 1.370667 -73.9932 40.7222
3 0.933232 -73.9772 40.7559
4 1.268699 -73.9932 40.7628
5 1.265304 -73.9932 40.7429
6 1.193437 -73.9852 40.7447

I created a map using the following code:

map <- ggmap::get_map("new york", zoom = 11)
nyc_map <- ggmap::ggmap(map, legend="topleft")

This map is displayed correctly.

I also created a layer with my data view:

ggplot(aes(LON,LAT, fill = TIP), data=as.data.frame(trip)) + 
geom_tile() + 
scale_fill_continuous(low="white", high="blue") + 
coord_equal()

And it is also generated and displayed.

The problem is when I want to do this:

nyc_map + 
ggplot(aes(LON,LAT, fill = TIP), data=as.data.frame(trip)) + 
geom_tile() + 
scale_fill_continuous(low="white", high="blue") + 
coord_equal()

I get the following error:

Error in p + o : non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.gg", "Ops.data.frame") for "+" 

I would be grateful if you could help me join these two facilities.

+4
source share
1 answer

Looking at your data, it is better to use geom_pointinstead geom_tile. The reason for this is that such data types are better visible on the map.

, ggmap ggplot :

library(ggplot2)
library(ggmap)

nyc_map <- get_map("new york", zoom = 12, maptype = "hybrid")

ggmap(nyc_map) + 
  geom_point(data=trip, aes(x=LON, y=LAT, fill=TIP), size=6, shape=21, position="jitter") + 
  scale_fill_continuous(low="white", high="blue")

:

enter image description here

position="jitter", .

:

trip <- read.table(text="TIP      LON     LAT
1.318878 -73.9932 40.7223
1.370667 -73.9932 40.7222
0.933232 -73.9772 40.7559
1.268699 -73.9932 40.7628
1.265304 -73.9932 40.7429
1.193437 -73.9852 40.7447", header=TRUE)
+5

All Articles