R:忽略GEOM_SF填充量表的异常值
我试图用计算趋势的值填充我的情节的多边形。我的大多数情节都很好。但是,我想绘制的两个变量具有少数极高的值。 我不想去除这些极端。我只想告诉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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论