r - Changing the colour of a dodged barplot in ggplot2 -


i'm struggling change default colours of barplot made. since used value aes(fill="") argument addition of scale_colour_x or scale_fill_x not work. i'll provide code have , hope you'll find easy way solve problem me.

set.seed(123) platelay <- data.frame(rown = rep(letters[1:8], 4),                        coln = rep(1:4,each = 8),                        colorvar = rnorm(32, 0.3, 0.2)) 

the example data (supposed part of 96 microwellplate different fluorescence readouts per well)

ggplot(platelay,aes(x=rown,y=colorvar,fill=coln)) +  geom_bar(position="dodge",stat="identity") 

the plot should give 5 bars (one each coln) per rown , want them have colours make easy distinguish each bar.

this looks right now: dodged barplot

as can see colours blend , scale shows not distinct values 1 4 halves. appreciate slightest bit of help, since i'm not familiar r or coding @ (just started learning last week).

you getting color because fill variable coln not factor. convert factor , can add required colors manually using scale_fill_manual(). can either give names of color or can give hex codes of required color.

ggplot(platelay,aes(x=rown,y=colorvar, fill = as.factor(coln)))+ geom_bar(position="dodge",stat="identity") +  scale_fill_manual(values = c("blue", "#e50000", "#cc0000","green")) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -