如何制作代表我的z值的色谱图例? [英] How do i make a color spectrum legend which represents my z values?

查看:124
本文介绍了如何制作代表我的z值的色谱图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使用灰度命令制作了3D散点图,其中第三维表示颜色渐变.但是,在尝试制作与之相符的图例时,我碰壁了.我已经有了想要的颜色范围,我只是不知道如何告诉R将它们变成图例.这是我的代码.

I have managed to use the grey scale command to make a 3D scatter plot with the third dimension representing a color gradient. I have hit a wall when trying to produce the legend that coincides with it though. I already have the range of colors I want I just dont know how to tell R to make them into a legend. Here is my code.

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和field,但我不必走这条路线.

zcolor is my z axis values and should be able to be used to produce my legend. I have tried working with various packages i.e. SDMTools and fields but I shouldnt need to go that rout.

推荐答案

尝试一下,

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()

这篇关于如何制作代表我的z值的色谱图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆