在r中使用scale_fill_manual在ggplot中的特定层

发布于 2025-01-29 11:47:50 字数 315 浏览 4 评论 0原文

我很难将我的栅格绘制和某些点为SF对象。我使用aes(color = ...)将颜色分配给我的观点的不同类型。但是我想将这些颜色更改为红色,蓝色和黄色等特定的颜色。另外,我不能使用scale_fill_manual,因为我的栅格层的颜色是第一层的,因此不应更改。有解决这个问题的解决方案吗? 提前致谢

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

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))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷梦 2025-02-05 11:47:50

填充参数aes您可以使用scale_fill_manual手动操作,可与多边形或栅格数据完美搭配。但是,当您需要着色时
或简单的行,color参数aes是。说,如果您想将不同的颜色掩盖到要点,使用Scale_color_manual,这不应干扰您的栅格颜色。

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.

趁微风不噪 2025-02-05 11:47:50

软件包“ ggnewscale”将在此问题中起作用。它允许在一个图中使用不同的尺度。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文