我有168个值的数据框 - 下面是一个例子:
[1] 10.20825145 10.49029738 9.47768668 11.37237685 9.77536685 -9.96578428 9.84730064 -9.96578428 -9.96578428 9.67701164 8.89308834
[12] -9.96578428 -9.96578428 -9.96578428 4.88074954 10.83777007 9.67240471 11.55113265 12.29597119 11.17761580 1.27119342 5.89488206
[23] 11.04314439 11.51956302 8.88611025 0.41593543 10.09092012 1.11935342 2.29304065 6.44051757 7.27223875 4.17286046 12.29597119
[34] 8.93756226 -9.96578428 2.82374114 -9.96578428 -9.96578428 6.78451866 6.75725141 3.30799055 1.33285052 11.10138287 9.56310341
[45] 6.05138487 11.16478498 0.64163540 2.25818628 6.84610893 0.90170156 5.03961679 8.06503755 1.91447714 1.99289237 10.05683543
[56] 4.18387615 1.44569558 9.44208535 10.76103696 10.07250772 5.65824078 11.44590482 4.98525549 9.27145969 4.62079778 -9.96578428
[67] -0.15866721 7.84066444 10.64691705 8.10132712 10.42130331 7.63017724 9.81489036 10.44605958 7.61256542 10.59292091 10.68115428
[78] 8.63528904 7.08127497 9.37016682 9.72611928 8.79221371 11.37733558 10.13409536 8.54228484 9.19473411 9.22357213 -9.96578428
[89] 2.06859467 7.85102680 10.21632083 7.32085557 7.17868855 7.29012838 9.39064690 11.21826736 0.99311790 10.73680716 -1.27079596
[100] 1.56468983 -1.53765829 1.52571260 7.59811777 11.25804316 5.76919580 1.46352533 10.66897438 -0.19396590 -9.96578428 -0.10920277
[111] 10.27374790 1.86021231 0.05229581 9.10927587 6.75497052 -9.96578428 7.37624442 -1.18384163 10.09532648 10.66210443 0.97845531
[122] -0.58780829 1.70242105 7.11891287 -1.00259672 -9.96578428 3.44482985 3.66543196 2.30526333 9.25052252 0.47603010 0.67767918
[133] 0.53495561 -9.96578428 -0.25681726 -0.88592846 12.28143934 11.48635730 1.57340309 1.81157359 5.22452852 2.82243460 2.63202605
[144] 10.96672824 11.39766334 6.32855877 3.35147803 1.85503403 11.07168816 0.62804624 1.26195498 1.84045927 2.36940606 10.72429922
[155] 9.03370799 0.17404750 0.35583693 0.01601167 8.74355131 10.53061214 -1.02983443 -9.96578428 11.00097153 2.29188360 4.60733174
[166] 0.72027563 1.33766127 -1.02773393
我知道想绘制一个图形,每个数据点的颜色从红色变为绿色,值增加。我想保留数据框的顺序。
numbers <-(dataframe)
my_palette <- colorRampPalette(c("red", "yellow", "green"))(168))
plot(col= my_palette,numbers, pch=20)
但是,这会按数据帧索引的升序绘制颜色,而不是值。
如何解决这个问题的任何建议将不胜感激。谢谢
答案 0 :(得分:0)
而不是col = my_pallete
,请使用col = my_pallete[rank(numbers)]