I have created a tile plot using a custom scale_file_gradientn palette, but the colours aren't quite right - and correcting it is a massive pain. The image shows the current version, though without axis labels (data not yet ready to be shared.).
Instead, I'd like to use the heat.colors palette. (I need the 0 value to be white, so viridis and similar palettes are not a good option here, I think).
However, I am struggling to find the right code for incorporating heat.colours into the ggplot2 geom_tile function. Can anyone advise?
Below is the code for my previous version using the custom palette, in case it is helpful.
ptile<-ggplot(dftabtile, aes(y=Var1, x=icd_ord, fill=Freq))
ptile<- ptile + geom_tile(color="Black", size=0.1) + coord_equal() + labs(y = "y values", x="x values" ) + theme_minimal() + xangle_theme
tile_red <- ptile + scale_fill_gradientn(colours=c("white", "#f2e8eb", "#e5d2d7","#d8bcc3", "#cba6af","#be909c", "#b17a88", "#a46474", "#974e60", "#8a384c","#7d2239"), values=c(0,0.0001,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), name="# Data points")
tile_red
ggsave("demo.png", width=400, height=200, units="mm")
I don't know if it might help cause you didn't provide your data, but have you tried using scale_fill_brewer
instead of scale_fill_gradient
?
library(tidyverse)
library(RColorBrewer)
display.brewer.all()
ftabtile %>%
ggplot(aes(y=Var1,
x=icd_ord,
fill=Freq)) +
geom_tile(color="Black", size=0.1)+
coord_equal() +
labs(y = "y values", x="x values" ) +
theme_minimal() +
xangle_theme +
scale_fill_brewer(palette = "Blues")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.