oswaldosantos / ggsn

R package to add north symbols and scale bars to maps created with ggplot or ggmap
http://oswaldosantos.github.io/ggsn/
GNU General Public License v2.0
161 stars 9 forks source link

The scale bar doesn't appear on my drawing #62

Open liufan612 opened 7 months ago

liufan612 commented 7 months ago

my code is below,and my figure 微信图片_20240123033555

ggplot()+ geom_raster(data=pm25_8099, aes(long, lat, fill=value))+ geom_sf(data=glo_shape, fill = NA, color = "black", size = 0.2)+ scale_fill_distiller(type = "div", palette = "RdYlBu",direction = -1,na.value=NA)+ labs(x ='Longitude',y="Latitude", title = "PM2.5_1980_1999_95th", )+ coord_sf(expand = FALSE,ylim = c(-60, 90))+ scale_x_continuous(limits = c(-180, 180), breaks = seq(-180, 180, 60))+ scale_y_continuous(limits = c(-60, 90), breaks = seq(-60, 90, 30))+ labs(fill="value")+ theme_bw()+theme( axis.text.x = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), axis.text.y = element_text(margin=unit(c(0.5,0.5,0.5,0.5), "cm")), axis.line = element_line(colour = "black"),
legend.position = "right", legend.background = element_rect(fill="transparent", size=2, linetype="blank", colour ="darkblue"), legend.text = element_text(colour="black", size=8, face="plain"), legend.title= element_text(colour="black", size=8, face="plain"), plot.margin = unit(c(0.5,0.5,0,0), "cm"), plot.title = element_text(face="bold",size=20,hjust = 0.5,vjust=0), axis.title = element_text(size = 12, face = 'bold'),
axis.text = element_text(size = 10) # )+
annotation_north_arrow( height = unit(0.5, "cm"), width = unit(0.5, "cm"), pad_x = unit(0.25, "in"), pad_y = unit(1.9, "in"), rotation = NULL, which_north='false',)+ ggsn::scalebar(data=pm25_8099,dist = 2000,dist_unit ='km', transform = TRUE, model = "WGS84", st.size = 50, location = 'bottomleft',y.min = -60, y.max = 90, x.min = -180, x.max = 180, box.fill = c("yellow", "black"), st.color = "black",height=0.01)

微信图片_20240123033555