0

I have a database df that has information of Covid effect for some countries in the world during January-July 2020. Following the code in https://www.youtube.com/watch?v=RrtqBYLf404 I have created the following dynamic map.

library(plotly)
graph = plot_geo(df, 
                 locationmode = "country-names",
                 frame = ~month) %>%
  add_trace(locations = ~iso,
            z = ~effect_covid_avg,
            zmin = min(df$effect_covid_avg),
            zmax = max(df$effect_covid_avg),
            color = ~effect_covid_avg,
            colorscale = 'Hot', #colorscale = 'heat', 'diverging',  #colorscale = 'YlOrRd',
            text = ~hover,
            hoverinfo = 'text')

graph

However, I want to take screenshots of some months so I can include them into a static pdf file. I want to make some modifications so to have:

  • Color of the palette (blue for positive, red for negative, whiter for 0). As you can see I have tried several palettes, not succesfully ('heat', 'diverging', 'YlOrRd').
  • Include the color legend inside the plot.

One of my screenshots looks like this. Covid effect

Any clue?

Thank you

vog
  • 770
  • 5
  • 11

1 Answers1

0
  1. By modifying the zmin and zmax to the same value with different sign you locate 0 in the middle.
  2. By changing "colorscale" to "colors" you can freely use the palettes. Therefore by applying "RdBu" you have the negatives in red and the positives in blue.

1 and 2 combined look like this:

graph = plot_geo(some_data_values, 
                 locationmode = "country-names",
                 frame = ~month) %>%
  add_trace(locations = ~iso,
            z = ~effect_covid_avg,
            zmin = -0.8,    # below the min (so 0 is at the center of the palette)
            zmax = 0.8,     # over the max (so 0 is at the center of the palette)
            color = ~effect_covid_avg,
            colors = 'RdBu', 
            text = ~hover,
            hoverinfo = 'text')
graph   

Still have to solve how to put the legend in the plot?

vog
  • 770
  • 5
  • 11