I want to plot USA raster using an Albers
coordination,codes as follows:
#both shp_f and ras_f are WGS84 coordination
shp_f <- 'USA.shp'
ras_f <- 'USA.tif'
Albers <- crs('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96
+x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs' )
shp <- readOGR(shp_f)
#convert raster cells as dataframe
ras_df <- ras_f %>% raster %>% rasterToPoints %>% as.data.frame
colnames(ras_df) <- c('x','y','val')
bm <- ggplot()+
geom_tile(data=ras_df,aes(x=x,y=y,fill=val))+
geom_polygon(data=shp,aes(x=long,y=lat,group=group),colour='grey',
fill=NA,linetype='solid',size=0.1)+
# convert plot coordination
ggalt::coord_proj(Albers)
This is a common Albers projection map with arc-shaped latitude lines, and
the xy labels are lon/lat degree. I want plot maps like it ,but it takes too much time to plot because convert each cell coordiantion in ggplot
is very slow especially when the high raster resolution. So I consider that change the raster projection first ,then plot it. hence the second section codes as follows:
#convert shape polygon coordination from WGS84 to Albers
shp_albers <- spTransform(shp, Albers)
ras_df <- ras_f %>% raster
#convert the raster coordination from WGS84 to Albers
%>% projectRaster(., res=50000,crs=Albers)
%>% rasterToPoints %>% as.data.frame
colnames(ras_df) <- c('x','y','val')
bm <- ggplot()+
geom_tile(data=ras_df,aes(x=x,y=y,fill=val))+
geom_polygon(data=shp_albers,aes(x=long,y=lat,group=group),colour='grey',
fill=NA,linetype='solid',size=0.1)
But this is a Cartesian graphic that xy is orthogonal (not a albers shape map). So the question is that: In general ,how to plot a proper shape map with it's projeciton (not a simple orthogonal graphic)? Meanwhile how to change the xy labels to lon/lat degree and plot arc-shape lon/lat lines (not use orthogonal lines)? The first figure is expected,but it plot too slow. The raster and shp file is here