Something is wrong with the code but I can't figure out what. I am trying to plot the coefficients of a geographically weighted regression on a map showing the districts of Barcelona. I can get R to plot the points or the map but I am unable to overlay them. What could be the issue?
ggplot(logairbnb, aes(x=x,y=y))+
geom_point(aes(colour=logairbnb$coefdist_center))+
scale_colour_gradientn(colours = terrain.colors(10),
guide_legend(title="Coefs"))
ggplot(neighbourhood_fortified, aes(long,lat,colour =
factor(id))) +
geom_polygon(fill = "white", colours =
terrain.colors(10))+coord_equal()
Something weird happens with the axes when I try to overlay the graphs
gwr.point1<-ggplot(logairbnb, aes(x=x,y=y))+
geom_point(aes(colour=logairbnb$coefdist_center))+
scale_colour_gradientn(colours = terrain.colors(10), guide_legend(title="Coefs"))
gwr.point1+
geom_polygon(data=neighbourhood_fortified,aes(long,lat,group=id),colour="grey")
The neighbourhood_fortified is in UTM coordinates while logairbnb is in geographic coordinates.
You should transform one of them. Since they are dataframe (as you told in comments), you have to convert first to
sfobjects and then transform the coordinates in one of them:Then you can use
geom_sfto plot them:Note: I used the most probable crs based on your plot coordinates, you should check the right crs in your data sources.
Note2: I didn't test the code chunks since I don't have your data.