Skip to content

Instantly share code, notes, and snippets.

@joannecheng
Created October 7, 2013 02:12
Show Gist options
  • Save joannecheng/6861610 to your computer and use it in GitHub Desktop.
Save joannecheng/6861610 to your computer and use it in GitHub Desktop.
Conditional Colors in R (from Visualize This)
# This is unnecessary:
# fillColors <- c()
# for (i in 1:length(hotdogs$Country)) {
# if (hotdogs$Country[i] == "United States") {
# fillColors <- c(fillColors, "#821010")
# } else {
# fillColors <- c(fillColors, "#aaaaaa")
# }
# }
barplot(hotdogs$Dogs.eaten, border=NA, names.arg=hotdogs$Year, xlab="Year", ylab="Number Eaten",
col=ifelse(hotdogs$Country=="United States", "#821010", "#aaaaaa"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment