0

I am trying to create a map depicting the Trade balance (Export minus Imports) of the European countries. I managed to create the map using the code below:

red_color <- "#6875B6"
white <- "#E4E5ED"
blue_color <- "#B66B68"

red_blue_palette <- colorRampPalette(c(blue_color, white, red_color))
colors_map <- red_blue_palette(10)


ggplot(merged) +
 geom_sf(aes(fill = value), color = NA, alpha = 0.9) +
 geom_sf(data = borders, fill = NA, size = 0.1, col = "grey30") +
 coord_sf(
   xlim = c(2377294, 6500000),
   ylim = c(1413597, 5228510)
 ) + scale_fill_gradientn(colours = colors_map) + theme_void()

It resulted in the following map:

Created Map

Now the problem is that some countries appear in red, even though they have a positive trade balance, and ideally they should appear in blue. I would be grateful if anyone can give me a clue as to how to put white at exactly zero, so that countries with a positive trade balance appear in blue instead of red. Thanks.

For those who want to have a look at the merged data:

> merged
Simple feature collection with 28 features and 6 fields
Geometry type: GEOMETRY
Dimension:     XY
Bounding box:  xmin: -2823918 ymin: -3076004 xmax: 10025920 ymax: 5307045
Projected CRS: ETRS89-extended / LAEA Europe
First 10 features:
CNTR_ID               CNTR_NAME ISO3_CODE NAME_ENGL FID        value                       geometry
 1       AT              Österreich       AUT   Austria  AT  -6381716162 POLYGON ((4832035 2857837, ...
 2       BE Belgien-Belgique-België       BEL   Belgium  BE  41394515352 MULTIPOLYGON (((4040360 307...
 3       BG                България       BGR  Bulgaria  BG  -5417941798 POLYGON ((5803878 2477397, ...
 4       CY           Κύπρος-Kıbrıs       CYP    Cyprus  CY  -9656348012 POLYGON ((6474836 1660347, ...
 5       CZ         Česká Republika       CZE   Czechia  CZ  37209855668 POLYGON ((4660256 3095529, ...
 6       DE             Deutschland       DEU   Germany  DE 366419598458 MULTIPOLYGON (((4283725 352...
 7       DK                 Danmark       DNK   Denmark  DK  18998047850 MULTIPOLYGON (((4283725 352...
 8       EE                   Eesti       EST   Estonia  EE  -1692446146 MULTIPOLYGON (((5333199 417...
 9       EL                  Ελλάδα       GRC    Greece  EL -35943725068 MULTIPOLYGON (((5675519 221...
 10      ES                  España       ESP     Spain  ES -31594000966 MULTIPOLYGON (((3367336 232...

I tried the solution suggested in the comments and I obtained the following:

enter image description here

How can I increase the contrast? Some countries, like Denmark, look almost white, although Denmark has 19 Billion Euros of surplus.

Saïd Maanan
  • 511
  • 4
  • 14
  • 1
    Please add data to make the question reproducible paste the output of `dput(merged)` into the question or a subset of the data with say two or three countries. Maybe `scale_fill_gradient2` could help as this has an argument `mid` – Peter Jan 22 '22 at 08:34
  • 2
    Difficult to test code without any data, but you may want to try `scale_fill_gradient2` instead. It takes slightly different arguments and has default values for low, mid and high of muted red, white and muted blue. – neilfws Jan 22 '22 at 08:34
  • @neilfws I tried the `scale_fill_gradient2` and it puts the zero exactly where I want it, but since there is a big difference between countries, most of them look white. – Saïd Maanan Jan 22 '22 at 08:48
  • 3 solutions. 1) use `scale_fill_grandientn` and create a custom gradient that changes colour quicker around 0. 2) Scale the column used for colouring using `scale` or normalizing, but manually set the break labels (and maybe the breaks themselves) using `scale_fill_gradient(breaks = ..., labels = ....)`. An alternative transformation would be `sign(x) * log(abs(x))` which may work well here. 3) Use another measure, for example "Surplus over gpd". Countries have different size economies, and comparing their surplus value does not really give any useful insight. – Oliver Jan 22 '22 at 08:59
  • or surplus per capita (dividing by number of residents). – Oliver Jan 22 '22 at 09:05
  • @Oliver Thank you for the suggestions. I believe the second solution is suitable for my case, since I am trying to visualize data that I have been assigned, and variables like GDP and population are not in that data. – Saïd Maanan Jan 22 '22 at 09:13

0 Answers0