I am trying to assign different colour scales to my dataset based on the column variable. The dummy code is
df1 <- data.frame(ID = c('a1', 'b1', 'c1', 'd1', 'e1', 'f1'),
var1 = c('a', 'b', 'c', 'a', 'b', 'c'),
var2 = c(0.006, 0.04, .005, 0, 0.02, 0.05))
Instead of an overall colour scale, I want 'a' from var1 to be red to white, 'b'blue to white, and 'c' as purple to white. I have 4000 rows in my actual data, I tried to nest each on top of each other, but failed.. the running is below. Please suggest where do I need to make the changes to get my desired output.
P.S.I know, the var2 will have different high's and lows, if legend is available, great, otherwise I just need to show color differences.
ggplot(df1,aes(y = var1, x = ID, fill = var2)) +
geom_tile(color = "white") +
coord_equal() +
scale_fill_gradient(low = "steelblue", high = "white") +
ylab("var1") +
xlab("ID") +
theme(legend.title = element_text(size = 10),
legend.text = element_text(size = 12),
plot.title = element_text(size = 16),
axis.title = element_text(size = 14, face = "bold"),
axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(fill = "ABC association")