0

I would like to generate a colour gradient plot from a df in R. The df has 2 column, the first is a colour code and the second a number. So my plot only has one dimension in the X with a colour in the Y if that makes sense.

>  dput(tail(df1, n=50))
structure(list(colours = c("#ADC07D", "#B5C272", "#C1C462", "#C2C460", 
"#DCC93D", "#DDC93C", "#DDC93B", "#EACB28", "#EACA28", "#E9C723", 
"#E7C31D", "#E7C21C", "#E7C019", "#E7C019", "#E5BD14", "#E5BC13", 
"#E4B80D", "#E3B70C", "#E3B60A", "#E29F00", "#E29C00", "#E39700", 
"#E48E00", "#E58900", "#E67E00", "#E77C00", "#E77700", "#E86B00", 
"#EB5800", "#EB5600", "#EB5100", "#EE3B00", "#EE3800", "#EE3700", 
"#EE3700", "#EF2E00", "#EF2A00", "#F02600", "#F11E00", "#C74024", 
"#B14830", "#91503F", "#90503F", "#90503F", "#90503F", "#90503F", 
"#90503F", "#90503F", "#90503F", "#90503F"), `V(network)$Forage` = c(0.362260261, 
0.380421546, 0.405517922, 0.407835536, 0.46340053, 0.466050869, 
0.466896832, 0.503383988, 0.506171832, 0.532890572, 0.566618979, 
0.575902496, 0.594105734, 0.594567821, 0.622845671, 0.628271573, 
0.664540722, 0.669849631, 0.679252365, 0.768537524, 0.774211483, 
0.782423082, 0.79637798, 0.805285302, 0.824000365, 0.826130001, 
0.835771962, 0.854854452, 0.886121785, 0.889545423, 0.898957372, 
0.935814146, 0.939427578, 0.941018492, 0.941519951, 0.957215867, 
0.963820732, 0.969986584, 0.983963985, 0.994455535, 0.996758715, 
0.999923838, 0.999999791, 1, 1, 1, 1, 1, 1, 1)), row.names = c(19L, 
115L, 37L, 46L, 11L, 14L, 124L, 42L, 49L, 70L, 118L, 13L, 4L, 
116L, 17L, 71L, 95L, 22L, 113L, 43L, 114L, 122L, 48L, 102L, 35L, 
36L, 9L, 40L, 44L, 119L, 25L, 26L, 38L, 33L, 41L, 106L, 96L, 
45L, 1L, 101L, 39L, 99L, 98L, 3L, 18L, 27L, 29L, 34L, 97L, 100L
), class = "data.frame")

So far I am able to generate what I want but it looks ugly

> image(as.matrix(df1$`V(network)$Forage`), col = df1$colours)

enter image description here So I was wondering if there are other cleaner ways to do this.

jay.sf
  • 60,139
  • 8
  • 53
  • 110

0 Answers0