how to costum the color palette for ggplot2
1
0
Entering edit mode
17 months ago

Hi, I use the following code to get the heatmap (figureA):

My code: enter image description here

Figure A enter image description here

However, I don't quite like the color (scale color and color bar). How could I modify the color as the Figure B (only care about the colors).

Figure B enter image description here

Thank you!

ggplots • 929 views
ADD COMMENT
0
Entering edit mode

Not sure if I understood the problem - do you want a different "red" tonality? Here you can find the different colors in R. Just replace the "#EA3323" by your color of interest.

ADD REPLY
0
Entering edit mode

Thank you! The R colors cheat-sheet is wonderful!

ADD REPLY
0
Entering edit mode
17 months ago

You can use scale_fill_gradient2() instead of scale_fill_gradient() to have a few more arguments to customize. In particular by setting a mid color or moving the midpoint to a particular numeric value, you can adjust the gradient to your liking.

scale_fill_gradient2(
  ...,
  low = "white",
  mid = "red50",
  high = "red",
  midpoint = 0.02,
  space = "Lab",
  na.value = "grey50",
  guide = "colourbar",
  aesthetics = "fill"
) 

You can also choose your desired colour with various online tools (search for "Hex colour picker"), if you need an exact matching colour to some template.

To change the appearance of the legend, e.g. make the bar smaller you can use the legend options of theme(), e.g. legend.key=element_rect() and legend.key.text=element_text(). Like so, you can for example highlight the breaks in black or make the legend width smaller.

I hope this helped. Best Matthias

ADD COMMENT

Login before adding your answer.

Traffic: 1828 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6