Medium test for R org gsoc:
library(tidycensus)
census_api_key("2a3a25db946201b88045dfeddcde2fc9b997ff08",install = TRUE)
Your API key has been stored in your .Renviron and can be accessed by Sys.getenv("CENSUS_API_KEY").
To use now, restart R or run `readRenviron("~/.Renviron")`
[1] "2a3a25db946201b88045dfeddcde2fc9b997ff08"
library(ggplot2)
#loading the required libraries
median_age=get_decennial(geography = "county",variables ="P013F001",state=06,geometry = TRUE)
Getting data from the 2010 decennial Census
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using Census Summary File 1
#loading the required data from tidy census using the get_decennial function. The get_decennial function returns the data for the specified variable and geography level. By using geometry= TRUE, can get information which is used for spatial data analysis in R.
plot(median_age["value"])
ggplot(median_age) +
geom_sf(aes(fill=value),color = "white",
linetype = 5,
lwd = 0.3)+ scale_fill_viridis_c(option = "F")+
labs(title = "County wise distribution of median age in california",
subtitle = "Deccenial census(2010)",
fill = "Median age" )+ theme_grey()
#making choropleth maps is easy using the ggplot library.geom_sf is used to visualize the sf data in r. the aes(fill=value) will visualize the specified data i.e. values based on colors in r. to modify the color and the themes in r, scale_fill_virdis is an excellent option as it allows us to use different color palettes