问题描述
我有3个方面,我想情节,我想第三个维度是颜色。
这将是在研发的方式。例如,我的数据看起来像这样
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.任何建议的软件包?请用具体的例子。谢谢!
jet.colors< -
colorRampPalette(C(#00007F,蓝,#007FFF,青色,
#7FFF7F,黄,#FF7F00,红,#7F0000))
图(X,Y,COL = jet.colors(12)[Z],ylim = C(0,100),PCH = 20,CEX = 2)
传说(8.5,90,COL = jet.colors(12)[Z],传奇= Z,PCH = 15)
如果你想查询你可以用Z值标记点着色:
文本(X,Y + 2,标签= Z)#offset垂直看颜色
另一种选择是使用包装:阿克玛这确实对插值不规则的(非)-grids:
要求(阿克玛)
要求(格子)
ak.interp< - 插值(X,Y,Z)
PDF(文件=out.pdf)
levelplot(ak.interp $ Z,主要=阿克玛输出绘制了格子:: levelplot,轮廓= TRUE)
dev.off()
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!
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
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()
这篇关于使用颜色作为第三维的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!