Note that there are some explanatory texts on larger screens.

plurals
  1. POcolor key legend in r
    primarykey
    data
    text
    <p>I am trying hard to figure out to add color gridient label to my plot ( <a href="https://stackoverflow.com/questions/10405967/barplot-in-loop-in-r">link to previous question</a>). Sorry for keep asking but this is maximum I could push me forward.</p> <pre><code>#data 1: lab1 &lt;- 1:10 group &lt;- rep(1:3, each = length (lab1)) label &lt;- rep(lab1, 3) avar &lt;- rep(c(0, 1, 4, 5, 6, 8, 10, 11, 12, 13), 3) myd &lt;- data.frame (group, label, avar) # data 2 fillcol &lt;- rep(rnorm(length(lab1)-1, 0.5, 0.2), 3) group1 &lt;- rep(1:3, each = length(fillcol)/3) # this variable will be used to fill color in bars filld &lt;- data.frame(group1, fillcol) colbarplot &lt;- function(group) { myd1 &lt;- myd[myd$group == group,] filld1 &lt;- filld[filld$group1 == group,] blues &lt;- colorRampPalette(c("yellow", "blue")) barplot(as.matrix(diff(myd1$avar)), horiz=T, col=blues(10)[10* filld1$fillcol], axes=F, xlab="Mark") axis(1, labels=myd$label, at=myd$avar) axis(3, labels=myd$avar, at=myd$avar) } par(mfrow = c(4, 1)) par(mar = c(2.5, 1, 2.5, 1)) sapply(unique(myd$group),function(x) colbarplot(x)) </code></pre> <p>Now I am struggling to add legend, sorry for this new user. </p> <pre><code> blues &lt;- colorRampPalette(c("yellow", "blue")) colors &lt;- blues(10) count &lt;- length(colors) m &lt;- matrix(1:count, count, 1) m1 &lt;- m image(m, col=colors, ylab="", axes=FALSE) </code></pre> <p>I produced color scale that is not what I am expecting, I am trying plot a smaller legend, less in width and height, along with original scale use in color coding. </p> <p><img src="https://i.stack.imgur.com/b9ASn.jpg" alt="enter image description here"></p> <p>Here are some unsuccessful trials for labeling: </p> <pre><code> colab &lt;- c(round (min(filld$fillcol), 2), round(max(filld$fillcol), 2)) colpos &lt;- c(0.33 * max(mapdat$position),0.66 * max(mapdat$position)) axis(1, labels=colab, at=colpos) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload