简体   繁体   中英

use scale_fill_manual in R for a specific layer of layers in ggplot

I have trouble for plotting my raster and some points as sf object over that. I use aes(color=...) to assign color to different types of my points. But I want to change the colours to specific ones like red and blue and yellow. also I can't use scale_fill_manual because my raster layer's colours which is in first layer, shouldn't be changed. Is there any solution for this problem? thanks in advance

geom_raster(data=dem2,aes(x=x,y=y,fill=elevation))+
geom_sf(data=mypoint,aes(shape=Type,colour=ranges))

The fill parameter inside aes wich you can manipulate manually using scale_fill_manual works perfectly with polygons or raster data. But, when you need to color points or simple lines, the color parameter inside aes is prefered. Said that, if you want to assing different colors to your points, use scale_color_manual , this shouldnt interfer in your raster color.

package "ggnewscale" will work in this problem. It allows to use different scale for color in one plot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM