R:忽略GEOM_SF填充量表的异常值

发布于 2025-02-12 02:07:33 字数 883 浏览 1 评论 0原文

我试图用计算趋势的值填充我的情节的多边形。我的大多数情节都很好。但是,我想绘制的两个变量具有少数极高的值。 我不想去除这些极端。我只想告诉geom_sf()以不同的方式上色,而通常应该为较轻的橙色涂上较大的值。

我附上了一个与我所遇到的问题所做的剧情的示例。如您所见,量表的范围在数千个,但我需要更像-1到2。我还包括了我用于上下文的绘图代码的片段。

这只是使用scale_fill_xxx正确功能的问题吗?有很多值得关注的地方,即使是一些指导,这将是一个巨大的帮助。

我需要的趋势图。请注意,由于几个异常值,众多的值。 “

我的代码:

library(tidyverse)
library(sf)
library(rgdal) # shapefiles from before
ggplot() + 
geom_sf(data=hydro_areas, colour="black", lwd=0.15) + # hydrometric areas
geom_sf(data=inla_results, aes(fill=rk.bsg.up), lwd=0.3, col="black") + # trends to plot
# setting scales
scale_fill_gradient2(name="Trend",
                    low="blue", mid="white", high="orange",
                    midpoint=0) +
xlab("Longitude") + ylab("Latitude") + theme_bw()

I am trying to fill the polygons of a plot of mine with values of a calculated trend. Most of my plots work well. However, two of the variables I want to plot have a small number of extremely high values. I would not like to remove these extremes. I would simply like to tell geom_sf() to colour them differently whilst normally large values should be coloured a lighter orange.

I've attached an example of a plot I made with the issue I'm having. As you can see, the range of the scale is in the thousands but I need it to be more like -1 to 2. I have also included a snippet of the plotting code I'm using for context.

Is this just an issue of using a scale_fill_xxx function correctly? There are so many to look at, even some guidance on that would be a huge help.

Plot of the trends I require. Note the huge range of values thanks to the few outliers.
1

My code:

library(tidyverse)
library(sf)
library(rgdal) # shapefiles from before
ggplot() + 
geom_sf(data=hydro_areas, colour="black", lwd=0.15) + # hydrometric areas
geom_sf(data=inla_results, aes(fill=rk.bsg.up), lwd=0.3, col="black") + # trends to plot
# setting scales
scale_fill_gradient2(name="Trend",
                    low="blue", mid="white", high="orange",
                    midpoint=0) +
xlab("Longitude") + ylab("Latitude") + theme_bw()

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文