使用颜色作为第三维度 [英] Using color as the 3rd dimension
问题描述
我有 3 个要绘制的维度,我希望第三个维度是颜色.
I have 3 dimensions that I want to plot, and I want the third dimension to be color.
顺便说一下,这将在 R 中.例如,我的数据看起来像这样
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]
我正在尝试使用filled.contour,但它给了我一个错误,说x 和y 必须按递增顺序排列.但我不太确定如何安排我的数据,以便这是真的.因为如果我按升序排列 x,那么 y 就不会升序了.
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.
我也可以使用非填充轮廓方法,其中只是着色的数据点.我怎样才能在 R 中做到这一点.任何建议的包?请用具体的例子.谢谢!
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!
推荐答案
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 值标记点:
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
另一种选择是使用 package:akima 对不规则(非)网格进行插值:
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()
这篇关于使用颜色作为第三维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!