Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2 shade colors according to column values
    primarykey
    data
    text
    <p>I have the following dataset:</p> <pre><code>cond &lt;- gl(15,1,labels=c("a1","a2","a3","a4","a5","b1","b2","b3","b4","b5","c1","c2","c3","c4","c5")) pos &lt;-c(rep("a",5),rep("b",5),rep("c",5)) mean &lt;- c(3.202634, 3.819009, 3.287785, 4.531127, 3.093865, 3.360535, 4.084791, 3.886960, 3.297692, 4.281323, 2.418745, 3.759699, 3.553860, 4.812989, 1.606597) hd &lt;- c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE) df &lt;- data.frame(cond,pos,mean,hd) </code></pre> <p>...and generated this plot</p> <pre><code>library(ggplot2) b &lt;- ggplot(df, aes(x=cond, y = mean, fill=pos)) + labs(x = "X", y="Y", fill=NULL) c &lt;- b + geom_bar(stat = "identity", position="dodge") + theme(text = element_text(size=18), axis.text.x = element_text(colour="black", size = 14)) + scale_fill_brewer(palette="Set1") my_theme &lt;- theme_update(panel.grid.major = element_line(colour = "grey90"), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.ticks = element_blank(), legend.position = "none") </code></pre> <p><img src="https://i.stack.imgur.com/sZ3LA.png" alt="enter image description here"></p> <p>Now I would like to adjust the colors according to the <code>hd</code> column of the dataframe such that every column of the barplot gets a slightly darker shade of the respective color (e.g. dark red instead of red) if <code>hd=="TRUE"</code>.</p> <p>How can I achieve that?</p> <p>And an additional question: How can I increase the distance between the <code>labs</code> X and Y and the plot/the axes?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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