简体   繁体   English

使用 R 中的 scale_fill_manual 用于 ggplot 中的特定图层层

[英]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.我无法在上面绘制我的栅格和一些点作为 sf 对象。 I use aes(color=...) to assign color to different types of my points.我使用aes(color=...)为我的不同类型的点分配颜色。 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.我也不能使用scale_fill_manual因为我的第一层光栅层的颜色不应该改变。 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.您可以使用scale_fill_manual手动操作的aes中的fill参数与多边形或栅格数据完美配合。 But, when you need to color points or simple lines, the color parameter inside aes is prefered.但是,当您需要对点或简单的线条进行着色时,首选aes中的color参数。 Said that, if you want to assing different colors to your points, use scale_color_manual , this shouldnt interfer in your raster color.说,如果您想为您的点分配不同的颜色,请use scale_color_manual ,这不应该干扰您的光栅颜色。

package "ggnewscale" will work in this problem.包“ggnewscale”可以解决这个问题。 It allows to use different scale for color in one plot.它允许在一个图中使用不同的颜色比例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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