All,
I am fairly new to programming and R, but have spent quite some time on this issue.
I am trying to overlay two maps, based on two different datasets. The first is a density map and the second is a geometric polygon. I can plot the two plots separately but when I plot them together I get the following message: "Error: Discrete value supplied to continuous scale". I tried adding inherit.aes= FALSE
as I suspected this could be an issue based on earlier posts, but it does not help
US_map=get_map(location="united states", zoom=4)
ggmap(US_map, extent="device")+
geom_polygon(inherit.aes=FALSE,
data=fortify(coords),aes(x=coords[,1],y=coords[,2], fill="orange",
colour="black", alpha=1))+
annotate("text",x=long_average,y=35,label=share_in_frame_perc,size=4)+
geom_density_2d(inherit.aes=FALSE, data=Mill_dots_T,aes(x=Mill_dots_T[,1],
y=Mill_dots_T[,2]), size=0.3)+
stat_density2d(data=Mill_dots_T,
aes(x=Mill_dots_T[,1], y=Mill_dots_T[,2],
fill=..level..,alpha=..level..), size=0.01, bins=16, geom="polygon")+
scale_fill_gradientn(colours = rev(rainbow(7)), breaks=c(0.006, 0.0125,
0.025, 0.05,0,01,0.02,0.03))+
scale_alpha(range= c(0.2,1), guide=FALSE)
My data looks a little bit like this:
Mill_dots_T
long_rect (first column)
-70
-70
-80
-80
-70
...
lat_rect (second column)
35
45
45
35
35
...
"Mill_dots_T" data looks like a little bit like this
Longitude (first column)
-86,8
-86,8
-86,8
-86,8
-86,3
-86,3
-86,3
-86,3
....
Latitude (second column)
33,5
33,5
33,5
33,5
33,5
32,3
32,3
32,3
32,3
32,3
32,3
32,3
32,3
32,3
....