为什么颜色与我输入scale_colour_manual的颜色不一样?
这是一个数据和代码示例:
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")
答案 0 :(得分:3)
这是因为您没有设置color=
美学,而是设置了fill=
美学。它们是不同的。而不是scale_colour_manual()
,请使用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