为什么ggplot geom_tile不尊重我的颜色首选项

为什么ggplot geom_tile不尊重我的颜色首选项

问题描述:

为什么颜色与我输入scale_colour_manual的颜色不一样?为什么ggplot geom_tile不尊重我的颜色首选项

这里的数据和代码示例:

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") 

这是因为你没有设置color=审美,您正在设置fill=美感。他们是不同的。使用scale_fill_manual()而不是scale_colour_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