3

This is my first time plotting in R, and I would greatly appreciate any help.

I have a dataframe df with two columns, region and value. The region column represents the FIPS codes and the values represents the number I want to plot with regards to the color scale ranging from 0-5000.

I looked at Shading counties using FIPS code in R map but I am not sure how to convert this gray scale shading to colors with either hex or rgb representation. In addition, I do not know how I would shade in colors based off a certain row's values.

This is the code I currently have, and it is plotting a map of the counties (all white) along with their borders.

library(maps)
library(dplyr)

data(county.fips)
year_df <- year_df[c("region", "value")]
counties <- county.fips %>% left_join(year_df, by=c('fips'='region'))
map("county", fill=TRUE)

Thanks in advance!

Community
  • 1
  • 1
Alan
  • 389
  • 3
  • 16

1 Answers1

4

The answer you linked to is really quite well done and provides a great reference for this question. I took the code in that answer and changed gray() to rainbow() like so:

df_pop_county$color <- rainbow(n = 50, y / max(y))

Which produced this: enter image description here

Stedy
  • 7,359
  • 14
  • 57
  • 77