使用颜色作为第三维度

发布于 2024-12-06 09:33:38 字数 381 浏览 0 评论 0原文

我想要绘制 3 个维度,并且我希望第三个维度是颜色。

顺便说一句,这将在 R 中进行。例如,我的数据看起来像这样,

x = [1,2,3,4,1,5,6,3,4,7,8,9]
y = [45,32,67,32,32,47,89,91,10,12,43,27]
z = [1,2,3,4,5,6,7,8,9,10,11,12]

我正在尝试使用filled.contour,但它给了我一个错误,指出x和y必须按递增顺序。但我不太确定如何安排我的数据以使其真实。因为如果我按升序排列 x,那么 y 将不会按升序排列。

对我来说,执行非填充轮廓方法也是可行的,其中只是着色的数据点。我怎样才能在 R 中做到这一点。有什么建议的包吗?请使用具体的例子。谢谢!

I have 3 dimensions that I want to plot, and I want the third dimension to be color.

This will be in R by the way. For instance, my data looks like this

x = [1,2,3,4,1,5,6,3,4,7,8,9]
y = [45,32,67,32,32,47,89,91,10,12,43,27]
z = [1,2,3,4,5,6,7,8,9,10,11,12]

I am trying to use filled.contour, but it giving me an error saying x and y must be in increasing order. But I'm not really sure how to arrange my data such that that is true. Because if I arrange x in increasing order, then y will not be in increasing order.

It is also feasible for me to do a non-filled contour method where it is just data points that are colored. How can I do this in R. Any suggested packages? Please use specific examples. Thanks!

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-12-13 09:33:38
jet.colors <-
   colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
                      "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
plot(x,y, col=jet.colors(12)[z], ylim=c(0,100), pch=20, cex=2)
legend(8.5,90, col = jet.colors(12)[z], legend=z, pch=15)

如果您想检查颜色,可以使用 z 值标记点:

text(x, y+2, labels=z)  #offset vertically to see the colors

在此处输入图像描述

另一种选择是使用 package:akima 对不规则(非)网格进行插值:

require(akima)
require(lattice)
ak.interp <- interp(x,y,z)
pdf(file="out.pdf")
levelplot(ak.interp$z, main="Output of akima plotted with lattice::levelplot", contour=TRUE)
 dev.off()

在此处输入图像描述

jet.colors <-
   colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan",
                      "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
plot(x,y, col=jet.colors(12)[z], ylim=c(0,100), pch=20, cex=2)
legend(8.5,90, col = jet.colors(12)[z], legend=z, pch=15)

And if you want to check the coloring you can label the points with the z value:

text(x, y+2, labels=z)  #offset vertically to see the colors

enter image description here

Another option is to use package:akima which does interpolations on irregular (non)-grids:

require(akima)
require(lattice)
ak.interp <- interp(x,y,z)
pdf(file="out.pdf")
levelplot(ak.interp$z, main="Output of akima plotted with lattice::levelplot", contour=TRUE)
 dev.off()

enter image description here

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