0

I'm in the process of trying to make a map. I've been following this guide but using my own data. I'm having trouble at the part where I make the data frame. I have a .csv file but every time I use the code to make the dataframe, I get this warning message:

Warning message:
In stri_match_first_regex(string, pattern, opts_regex = opts(pattern)) :
  argument is not an atomic vector; coercing

The .csv file I'm using has three columns: county, population, and growth rate. Here's the code I'm using:

x <- read.csv("data/ny_counties.csv")

pop_and_growth <- str_match(x, "^([a-zA-Z ]+)county\t.*\t([0-9,]{2,10})\t([0-9,]{2,10}) GrowthRate$")[, -1] %>%
  na.omit() %>%
  na.omit() %>%
  str_replace_all(",", "") %>% 
  str_trim() %>%
  tolower() %>%
  as.data.frame(stringsAsFactors = FALSE)

I'm not sure what's wrong here or how to fix it. Any advice?

Also, how do I zoom in on one county? I tried using the following but to no avail.

coord_fixed(xlim = c(-123, -121.0),  ylim = c(36, 38), ratio = 1.3)
M--
  • 25,431
  • 8
  • 61
  • 93
  • You need to ask a separate question about the maps. Each question should be limited to one question. – M-- Oct 11 '20 at 04:15
  • Welcome to Stack Overflow! You should provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It should be [minimal, but complete and verifiable example](https://stackoverflow.com/help/minimal-reproducible-example). Your question should be clear and specific. – M-- Oct 11 '20 at 04:17
  • You get this warning as you probably pass a data.frame x to `str_match`. However, you probably don't need the text scraping stuff as in the tutorial you linked. There they scraped some data from wikipedia which gave them a text file and which they had to clean up. But you already have the data in `ny_counties.csv` and when reading via read.csv you already get a nice dataframe with three columns. Simply check with e.g. `str(x)`. – stefan Oct 11 '20 at 06:48
  • @stefan I figured that part out - thank you so much for your help – CorydorasTrilineatus Oct 11 '20 at 17:33

0 Answers0