This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Ggplot2 In R: Adjusting The Midpoint Of The Scale_Fill_Gradient Bar?

I've been generating a heatmap using this snippet:

library(ggplot2)
p <- ggplot(res, aes(x=group, y=variable)) + 
  geom_tile(aes(fill = value), colour =   "yellow") + 
  scale_fill_gradient(low = "yellow", high = "red", name="p-value") +
  ggtitle("title") +
  theme(axis.text.x=element_text(angle=90)) +
  geom_text(aes(label=format(value,digits=2))) +
  labs(x="m1",y="m2")

print(p)

and I would like to add a mid color and adjust the midpoint of the color gradient to 0.05 in the manner found in scale_colour_gradient2(). Is there a way to do this with scale_fill_gradient()? I've been trying

d + scale_colour_gradient2(low = "red", mid = "black", high = "green", midpoint= 0.05, guide = "colourbar")

but I get "Error in unit(tic_pos.c, "mm" : 'x' and 'units' must have length > 0"

r

this is not a bioinformatics question nor has the bioinformatics context established or hinted at so it will be deleted

0 answers

No answers yet.

Log in to answer this question.