Skip to content

Instantly share code, notes, and snippets.

@briandk
Created February 8, 2012 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/1765194 to your computer and use it in GitHub Desktop.
Save briandk/1765194 to your computer and use it in GitHub Desktop.
Problems with scale_fill_manual in ggplot2 v0.9.0
# These problems are current as of
# commit fe93b8ae11c43f8e33cb0252a25d260a769d4ded in ggplot2
# A data frame with four levels of 'g'
dat2 <- data.frame(x=factor(1:5),
y=3,
g=c("B","A","C","D","D"))
p2 <- ggplot(dat2, aes(x=x,y=y,fill=g)) + geom_bar()
# OK with no scale added
p2
# OK: Scale with four values, order ABCD
p2 + scale_fill_manual(
values=c("A"="red",
"B"="green",
"C"="blue",
"D" = "orange"
)
)
# Not OK: Scale with five values, order ABCED
# D values show up as hollow bars
p2 + scale_fill_manual(
values=c("A"="red",
"B"="green",
"C"="blue",
"E" = "steelblue",
"D"= "orange"
)
)
# Not OK: Scale with eight values, order EFGHABCD
# All values show up as hollow bars
p2 + scale_fill_manual(
values=c("E" = "steelblue",
"F" = "pink",
"G" = "darkgreen",
"H" = "yellow",
"A"="red",
"B"="green",
"C"="blue",
"D"= "orange"
)
)
# Not OK: Scale with eight values, order AEFGHBCD
# Only the color for "A" (red) will appear
p2 + scale_fill_manual(
values=c("A"="red",
"E" = "steelblue",
"F" = "pink",
"G" = "darkgreen",
"H" = "yellow",
"B"="green",
"C"="blue",
"D"= "orange"
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment