Created
May 6, 2015 09:46
-
-
Save rtanglao/a0bf92971d158c9876fd to your computer and use it in GitHub Desktop.
correct bar graph using ggplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(sorted3,aes(x=colorname,y=count,fill=as.character(sorted3$colorname)))+ | |
stat_summary(fun.y=identity,geom="histogram")+ | |
scale_fill_manual(values=c(as.character(sorted3$colorname)),+ | |
name= "My name", guide = guide_legend(reverse = TRUE))+ | |
scale_x_discrete(limits = sorted3$colorname) |
so colours for labelling needs to be in hex not colour names!
c3 <- c("#1F78B4", "#F03B20", "#31A354")
ggplot(sorted3,aes(x=colorname,y=count,fill=c3))+ stat_summary(fun.y=identity,geom="histogram")+scale_x_discrete(limits = sorted3$colorname)+scale_fill_manual("Result", values = c3)
- sapply(d, identity) to make named vector
- https://gist.github.com/mmparker/6315074 - how to make named colors in ggplot2
getnumericColour <- function(colorname) {
- colour_matrix=col2rgb(colorname)
- return(as.numeric(colour_matrix[1,1]) * 65536 +
- as.numeric(colour_matrix[2,1]) * 256 +
- as.numeric(colour_matrix[3,1]))
- }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the colours are wrong! everything else is correct!