Heatmape <- function(TB, x, y, fill, minpoint = FALSE, midpoint = FALSE, maxpoint = FALSE, legend.name = expression(paste("Δ", log[10], "(", K[D], ")", sep = '')), axis.title.x = 'X', axis.title.y = 'Y', colors = c("Firebrick4", "white", "royalblue4") ){ if(minpoint == FALSE){ minpoint = min(TB[[fill]], na.rm = TRUE) } if(midpoint == FALSE){ midpoint = mean(c(min(TB[[fill]], na.rm = TRUE), min(TB[[fill]], na.rm = TRUE))) } if(maxpoint == FALSE){ maxpoint = max(TB[[fill]], na.rm = TRUE) } P <- ggplot(TB, aes(TB[[x]], TB[[y]], fill = TB[[fill]])) + geom_tile() + scale_fill_gradientn( colors = colors, values = scales::rescale(c(minpoint, midpoint, maxpoint)), oob = scales::squish, na.value = "gray", limit = c(minpoint, maxpoint)) + labs(x = axis.title.x, y = axis.title.y, fill = legend.name) + theme_linedraw() + coord_trans(expand = 0) + theme(panel.background= element_rect ('gray',), panel.grid = element_blank()) return(P) }
Heatmape(data, "X", "Y", "Z") + ggtitle("With default scale") Heatmape(data, "X", "Y", "Z", minpoint=1.5, midpoint =2, maxpoint=2.5) + ggtitle("given value range")
|