Sharif Amlani
Sharif Amlani

Reputation: 1278

how to manually change continuous scale color in tmap in R

How can I manually determine the colors on a continuous scale in tmap?

For example, I am working with a map similar to the one below:

data(World)
World$gdp_cap_est2 <- World$gdp_cap_est -100000
tm_shape(World) + tm_polygons(col="gdp_cap_est2",
                              style = "cont")
                                       

I'd like the color to be red for negative values, I'd like the color to be white at and around zero, and I'd like the color to be blue for positive values.

enter image description here

Thank you so much for the help!

Upvotes: 2

Views: 959

Answers (1)

Sharif Amlani
Sharif Amlani

Reputation: 1278

Use tmaptools::palette_explorer() to find the correct palette.

palette = "RdBu" is the most appropriate.

data(World)
World$gdp_cap_est2 <- World$gdp_cap_est -100000
tm_shape(World) + tm_polygons(col="gdp_cap_est2",
                              style = "cont",
                              palette = "RdBu")

Upvotes: 2

Related Questions