4
I am trying to reproduce the format of the map below, however, I have been facing some problems to insert these "straights" on the map. After a search, I found the package ggrepel
that brings with it a series of functions capable of accomplishing the desired. For more details see: https://ggrepel.slowkow.com/articles/examples.html.
I intend to insert a red dot in each state of the map with the "straight" coming out of it, and then add some numerical information, basically it would be next to the following example:
However, I have been facing the error that is being presented in the code below.
The data is available here: https://drive.google.com/file/d/1TuApNsGtVfNVcGOHmEB-5qVxObRa13V7/view?usp=sharing
library(geobr)
library(ggplot2)
library(ggrepel)
states <- read_state(code_state = "all",year = 2019)
states <- dplyr::left_join(states, dados, by = c("name_state" = "uf"))
ggplot(states) +
geom_sf(data = states, aes(fill = AreaTotal)) +
geom_sf_label(aes(label = states$abbrev_state),label.padding = unit(0.8, "mm"),size = 4)+
geom_point(data = states, color = "red")
Erro: geom_point requires the following missing aesthetics: x and y
Run `rlang::last_error()` to see where the error occurred.
Além disso: Warning messages:
1: Use of `states$abbrev_state` is discouraged. Use `abbrev_state` instead.
2: In st_point_on_surface.sfc(sf::st_zm(x)) :
st_point_on_surface may not give correct results for longitude/latitude data
````
In this example, you’re not even using the package
ggrepel
. For arrows you must choose betweengeom_label_repel()
orgeom_text_repel()
. Note that the two functions want the points/coordinates where the arrows/lines should be inserted. I suggest you consult this material here. The error shown in the functiongeom_point()
, values of x and y missing...– Rodrigo Silva
Thank you Rodrigo Silva!!
– user55546