user1357015
user1357015

Reputation: 11696

Why does ggplot geom_tile not respect my color preference

Why are the colors not the same as I input them into scale_colour_manual?

Here's a sample of data and code:

 temp <- dput(head(binaryHeatMapPlotData))
structure(list(Structure = c("1A00", "1A01", "1A02", "1A0U", 
"1A0Z", "1A1M"), method = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("iPAC4D", 
"iPAC3D", "graphPAC4D", "graphPAC3D", "spacePAC4D", "spacePAC3D"
), class = "factor"), value = structure(c(3L, 3L, 2L, 3L, 3L, 
2L), .Label = c("-1", "0", "1"), class = "factor")), .Names = c("Structure", 
"method", "value"), row.names = c(NA, 6L), class = "data.frame")

binaryHeatMapPlot <- ggplot(temp, aes(y=as.factor(Structure),x=method, fill = value))+
  scale_colour_manual(values = c("-1" = "white", "0" = "green", "1" = "blue"))+
  geom_tile() +
  ggtitle("Methodology Vs Cluster Detection By Structure")+
  xlab("Method")+ylab("Structure")

Upvotes: 1

Views: 243

Answers (1)

MrFlick
MrFlick

Reputation: 206546

This is because you are not setting the color= aesthetic, you are setting the fill= aesthetic. They are different. Rather than scale_colour_manual(), use scale_fill_manual().

binaryHeatMapPlot <- ggplot(temp, aes(y=as.factor(Structure),x=method, fill = value))+
  scale_fill_manual(values = c("-1" = "white", "0" = "green", "1" = "blue"))+
  geom_tile() +
  ggtitle("Methodology Vs Cluster Detection By Structure")+
  xlab("Method")+ylab("Structure")
binaryHeatMapPlot

Upvotes: 3

Related Questions