1

I would like to create a palette, my goal is to color the countries in proportion to how many meters they have in that country. How can I do it?

This is my dataset:

'

library(readxl)
library(sf)
library(raster)
library(dplyr)
library(spData)
library(spDataLarge)
library(tmap)    # for static and interactive maps
library(leaflet) # for interactive maps
library(ggplot2) # tidyverse data visualization package

mt <- data(metro)

metro %>% count(iso_a3)

map = tm_shape(world) + tm_fill() + tm_borders()

print(map)

'

Quinten
  • 35,235
  • 5
  • 20
  • 53
Lila
  • 72
  • 5

1 Answers1

1

The data set you are using is composed of points rather than polygons, so there are no borders or fills to draw. If you want to plot the points according to the counts, you can do:

data(metro)

metro %>% count(iso_a3) %>% tm_shape() + tm_bubbles(col = "n")

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • I need a map with countries not bubble, it is possible? – Lila May 02 '22 at 12:54
  • Not with this data set. You need a shapefile with the countries of the world on it. That's not what `metro` is. It's a collection of points. – Allan Cameron May 02 '22 at 12:55
  • Do you know the dataset? – Lila May 02 '22 at 12:58
  • Yes. The metro data set in tmap is a data frame of 436 points with associated population values over several years. It does not contain country outlines, only points indicating the location of cities. – Allan Cameron May 02 '22 at 13:17
  • Is it possible transform in country? – Lila May 02 '22 at 14:51
  • You could use the `World` data set that is included in tmap (`data("World")`). Transform it via `World %>% as_tibble()` to a tibble and join or add your data to each of the countries. – mgrund May 03 '22 at 05:57