如何使这代表我的z值的彩色光谱传奇?(How do i make a color spectrum

2019-10-17 09:51发布

我已成功地使用灰度命令使与代表颜色梯度的第三尺寸的三维散点图。 我已经打试图产生与它虽然一致的传说时,一堵墙。 我已经有颜色我想我只是不知道如何告诉R来使他们成为一个传奇的范围内。 这里是我的代码。

conocarp.stands<-c(264,330,400,594,600,700,726,730,800,825,825,826,1914,2145,2200,2310,2475,2640,3630,3960,3960,4124,4554,5082,8250,8475,9200,1000)

fimb.size<-c(540,2160,1100,1170,350,850,2340,600,200,738,1080,1300,2416,540,3565,810,648,0,900,0,635,1210,0,900,2340,1152,0,0)

sugar.visits.cono<-c(0.005682,0,0.065,0,0,0.010714,0,0.010274,0.011875,0,0,0,0,0,0.007045,0,0.001414,0.002273,0,0.014141,0.001263,0.006426,0.000769,0.000295,0.005515,0.000186,0.00359,0.004939)

colors <- rev(grey(1:101/101))
zcolor <- colors[round((sugar.visits.cono -min(sugar.visits.cono))/diff(range(sugar.visits.cono))*100 + 1)]
plot(conocarp.stands,fimb.size, pch=1, cex=1.8,ann=FALSE)
points(conocarp.stands,fimb.size,col=zcolor, pch=16, cex=1.5)

zcolor是我的Z轴值,应该能够被用来生产我的传说。 我曾尝试与工作各种包,即SDMTools和领域,但我不应该需要去那溃败。

Answer 1:

尝试这个,

library(ggplot2)

d = data.frame(conocarp.stands = conocarp.stands,
               fimb.size = fimb.size,
               sugar.visits.cono = sugar.visits.cono)

ggplot(data = d, mapping = aes(x = conocarp.stands, y = fimb.size)) +
     geom_point(aes(colour = sugar.visits.cono), shape = 19)

last_plot() + scale_colour_gradient(high="grey10", low="grey90") + theme_bw()


Answer 2:

使用raster.grid命令,我发现你也可以解决这个问题,但是我无法弄清楚如何标记轴。 谢谢你这么多巴蒂斯特我一直避免ggplots 2包,但我认为这是一次我在鸽子下面是使用raster.grid如果它可以帮助任何人我的代码:

库(网格)grid.raster(1:一百○一分之一百○一,宽度= 0.075,高度= 0.1)



文章来源: How do i make a color spectrum legend which represents my z values?