0

I am in the process of making a density map that will represent population density (more specifically, in Virginia) based on zip codes. I have followed the instructions that were given in the thread: Making a zip code choropleth in R using ggplot2 and ggmap (Essentially I copied the code)

However, whenever I tried feeding my own data, an error message occurs: Error in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y) : Can't join on 'region' x 'region' because of incompatible types (integer / character) In addition: Warning message: In min(xx[xx > upper]) : no non-missing arguments to min; returning Inf

The dataset that I want to use have the same format as "df_pop_zip". However, it just seems there is a problem with using my own data. To be more precise, "df_pop_zip" has two variables: "region"(zip code), and "value"(frequency of the zip code). I have created an excel sheet with two columns "region" and "value" with random zip codes and frequencies.

Can someone please provide any insight to this problem?

Thanks in advance, Martin

Community
  • 1
  • 1

1 Answers1

0

Sounds like you're trying to join by comparing a character to a numeric. Looks at the str() of the data you're reading in from excel to make sure you're joining like with like.

Adrian Martin
  • 780
  • 7
  • 21
  • Thanks for the reply, Adrian. – Chaconne1004 Apr 17 '17 at 19:11
  • However, I am not too sure on what you mean by comparing the two. The sample data that the author uses - 'df_pop_zip' looks like it has the same format as what my Excel data looks like, when I viewed both from Rstudio. – Chaconne1004 Apr 17 '17 at 19:19
  • Let's say you're running a join between data.frames a and b, matching by variable x. If you run class(a$x) and class(b$x), the result should be the same. Or, if you run str(a) and str(b), the results of those commands should show that the x variable is the same class in each dataframe. – Adrian Martin Apr 17 '17 at 19:30
  • Do you have any suggestions how I should proceed with this problem? I don't know how I should be looking into whether or not the Excel sheet is in a string mode or not. Any suggestion is welcome! – Chaconne1004 Apr 19 '17 at 20:05
  • Can you paste the results of str(x) and str(y)? – Adrian Martin Apr 20 '17 at 14:55
  • The data that ChoroplethrZIP package uses is - 'data.frame': 32989 obs. of 2 variables: $ region: chr "01001" "01002" "01003" "01005" ... $ value : num 17380 28718 11286 5120 14593 ... – Chaconne1004 Apr 20 '17 at 18:32
  • The data I am using is 'data.frame': 3 obs. of 2 variables: $ region: int 23223 24646 24649 $ value : int 10 15 400 – Chaconne1004 Apr 20 '17 at 18:32
  • [main] data.frame': 32989 obs. of 2 variables: $ region: chr "01001" "01002" "01003" "01005" ... $ value : num 17380 28718 11286 5120 14593 ... is the result of doing string for data that came with the package. – Chaconne1004 Apr 20 '17 at 18:39
  • Hey, sorry I didn't see this until now. So you're trying to join up an integer with a character. $ region: int 23223 etc etc is not going to join up correctly with $ region: chr 01001 etc etc. You need to either convert the integer column to a character column, or vice versa, before you can compare the two and find matches (which is what join needs to do). – Adrian Martin Apr 25 '17 at 01:31