How to make a map of Brazil

1

I'm trying to map the R for the first time. I've done all the necessary process with the data and I'm following the instructions of an available script here but it does not recognize the" longest "object.

Can you help?

The script looks like this:

#install.packages("pacman")
rm(list=ls())

pacman::p_load(tidyverse, janitor, haven, forcats, 
       formattable,
       knitr,stringr, hrbrthemes, 
       rgdal, mapproj, plotly)

CP <- read.table("/Users/marciarangelcandido/CP_UF.csv", sep = ";", header = TRUE)

CP <- CP %>% 
  mutate(Estado = case_when(Estado == "A3re" ~ "AC",
                            TRUE ~ as.character(Estado))) %>% 
  rename("sigla" = "Estado")


mapa <- read.csv("https://raw.githubusercontent.com/thiago-ms-cp/programacao_iesp/master/mapa_est_geral.csv")

library(descr)

mapa$sigla <- toUTF8(mapa$sigla, "IBM850")

#palette(c("#779999", "#99bbbb", "#bbdddd", "#ddffff"))
#plot(mapa, col = mapa$sigla)
#title("Mapa de Publicações da Ciência Política")


CP <- CP %>% 
  select(sigla, Estrato)

mapa <- mapa %>%
  left_join(CP, by = "sigla")

mapa<-mapa %>%
  group_by(sigla) %>% 
  mutate(a1= sum(Estrato==10)) %>%  
  mutate(a2=sum(Estrato==9)) %>%
  mutate(b1=sum(Estrato==8)) %>%
  mutate(b2=sum(Estrato==7)) %>%
  mutate(b3=sum(Estrato==6)) %>%
  mutate(b4=sum(Estrato==5)) %>%
  mutate(b5=sum(Estrato==4)) %>%
  mutate(c=sum(Estrato==3))

mapa$texto <- paste("A1 =", CP$a1, "revistas",
                  "; A2 =", CP$a2, "revistas",
                  "; B1 =", CP$b1, "revistas",
                  "; B2 =", CP$b2, "revistas",
                  "; B3 =", CP$b3, "revistas",
                  "; B4 =", CP$b4, "revistas",
                  "; B5 =", CP$b5, "revistas",
                  "; C =", CP$c, "revistas") 


mapa %>%
  plot_ly(~longest, ~latest, group = ~group)


plot_ly(mapa, lon = **longest**, lat = latest, text = texto,
        color = Estrato, type = 'scattergeo', locationmode = 'country names') %>%
  layout(title = 'Populations<br>(Click legend to toggle)')


mapa$Estado <- cut(mapa$Estado, 4)
levels(mapa$Estado)
    
asked by anonymous 12.12.2017 / 23:31

0 answers