ggplot2 - How to generate a map with density based on value, not amount of points in R? -


i using following data set:

head(trip_3)   tip     lon    lat 1   0    -73.866 40.741 2   10.0 -73.906 40.707 3   1.2  -73.706 40.738 4   2.0  -73.946 40.640 5   0    -73.946 40.625 6   1.5  -73.986 40.602 

i able generate following map present points high , low average tip values: enter image description here

i have achieved following code:

nyc_map + geom_point(data=as.data.frame(trip_3), aes(x=lon, y=lat, fill=tip), size=3,  shape=21, alpha=0.6, position="jitter") + scale_fill_continuous(low="white", high="#ff0033") 

now want map presenting areas (density) high , low tips not using points - want this: enter image description here

but counts amount of points, not bases on tip value. great achieve have described earlier. code used:

nyc_map + stat_density2d(aes(x=lon, y=lat, fill = ..level..), size=3, bins=10, data=as.data.frame(trip_3), geom="polygon") 

how make stat_density2d rely on tip, not amount of points?

try geom_contour. allows specify third variable z. geom_contour draw lines @ equal tip areas topographic map.

nyc_map + geom_contour(aes(x=lon, y=lat, z=tip, fill=tip), color="white") 

you can use stat_contour if want shade between lines.

nyc_map + stat_contour(aes(fill=..level..), geom="polygon", binwidth=250, alpha=.5) 

here's example. white lines drawn geom_contour. shading done stat_contour.

contour example image


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -