spplot() - 使 color.key 看起来不错
恐怕我又遇到了 spplot() 问题。
我希望 spplot() 中的颜色代表绝对值,而不是像 spplot 默认情况下那样代表自动值。
我通过从要绘制的变量中提取一个因子(使用命令 cut())来实现此目的。这工作得很好,但颜色键看起来一点也不好。
自己看看:
library(sp)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
meuse.grid$random <- rnorm(nrow(meuse.grid), 7, 2)
meuse.grid$random[meuse.grid$random < 0] <- 0
meuse.grid$random[meuse.grid$random > 10] <- 10
# making a factor out of meuse.grid$ random to have absolute values plotted
meuse.grid$random <- cut(meuse.grid$random, seq(0, 10, 0.1))
spplot(meuse.grid, c("random"), col.regions = rainbow(100, start = 4/6, end = 1))
我怎样才能让右侧的 color.key 看起来不错 - 我希望有更少的刻度和更少的标签(也许在 color.key 的每个极端上只有一个标签)
提前谢谢您!
[编辑] 为了清楚地说明绝对值的含义:想象一张我想要显示海高的地图。 Seaheight = 0(最小值)应始终显示为蓝色。 Seaheight = 10(仅作为示例,它是最大值)应始终显示为红色。即使地图上显示的区域没有海洋,这一点也不应该改变。 在我的示例中,我使用 cut() 命令实现了这一点。所以这部分工作正常。
这就是我的问题 我不喜欢的是右侧的颜色描述。有 100 个刻度,每个刻度都有一个标签。我想要更少的蜱虫和更少的标签。
I'm afraid I have a spplot() question again.
I want the colors in my spplot() to represent absolute values, not automatic values as spplot does it by default.
I achieve this by making a factor out of the variable I want to draw (using the command cut()). This works very fine, but the color-key doesn't look good at all.
See it yourself:
library(sp)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
meuse.grid$random <- rnorm(nrow(meuse.grid), 7, 2)
meuse.grid$random[meuse.grid$random < 0] <- 0
meuse.grid$random[meuse.grid$random > 10] <- 10
# making a factor out of meuse.grid$ random to have absolute values plotted
meuse.grid$random <- cut(meuse.grid$random, seq(0, 10, 0.1))
spplot(meuse.grid, c("random"), col.regions = rainbow(100, start = 4/6, end = 1))
How can I have the color.key on the right look good - I'd like to have fewer ticks and fewer labels (maybe just one label on each extreme of the color.key)
Thank you in advance!
[edit]
To make clear what I mean with absolute values: Imagine a map where I want to display the sea height. Seaheight = 0 (which is the min-value) should always be displayed blue. Seaheight = 10 (which, just for the sake of the example, is the max-value) should always be displayed red. Even if there is no sea on the regions displayed on the map, this shouldn't change.
I achieve this with the cut() command in my example. So this part works fine.
THIS IS WHAT MY QUESTION IS ABOUT
What I don't like is the color description on the right side. There are 100 ticks and each tick has a label. I want fewer ticks and fewer labels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方法是使用属性 colorkey。例如:
The way to go is using the attribute colorkey. For example:
首先,根本不清楚您在这里想要什么。有很多方法可以使 color.key 看起来“漂亮”,那就是首先了解传递给 spplot 的数据以及对其提出的要求。 cut() 提供完全格式化的间隔,例如 (2.3, 5.34],需要以不同的方式处理,增加绘图中的边距、标签的特定格式和间距等。这可能不是您想要的也许
您只想要对输入值进行四舍五入的
整数值(或 trunc()、ceil()、floor() ......)
First, it's not at all clear what you are wanting here. There are many ways to make the
color.key
look "nice" and that is to understand first the data being passed to spplot and what is being asked of it. cut() is providing fully formatted intervals like (2.3, 5.34] which will need to be handled a different way, increasing the margins in the plot, specific formatting and spacing for the labels, etc. etc. This just may not be what you ultimately want.Perhaps you just want integer values, rounded from the input values?
Round the values (or trunc(), ceil(), floor() them . . .)