Skip to content

Line Chart: missing x-axis variable #83

@ericclute

Description

@ericclute

When creating this line chart, the last year in my series does not display on the x-axis. Is there a way to force it to appear?

`years <- c(2010, 2016, 2021)

SUMMARIZE BY RACE/ETHNICITY

rcb_re_func <- function(year){

Pull PUMS data

setwd("C:/Users/eclute/Downloads")
rcb_raw <- get_psrc_pums(5,year,"h",c("PRACE","TEN","GRPIP","HINCP"))
setwd("J:/Projects/V2050/Housing/Monitoring/2023Update")
rcb <- rcb_raw

Filter to only renters, create income/rent burden groupings, rename race/ethnicity categories, combine Some other Race & Two or More Races

rcb <- rcb %>% filter(TEN=="Rented") %>%
mutate(
rent_burden=factor(case_when(GRPIP < 30 ~"Less than 30 percent",
between(GRPIP,30,50) ~ "Between 30 and 50 percent",
GRPIP > 50 ~ "Greater than 50 percent",
!is.na(GRPIP) ~ "No rent paid"),
levels=c("Greater than 50 percent",
"Between 30 and 50 percent",
"Less than 30 percent",
"No rent paid")),
PRACE=factor(case_when(grepl("Other Race|Two or More Races", PRACE) ~"Other or Multiple Races",
grepl("^Black ", PRACE) ~"Black",
grepl("^Hispanic ", PRACE) ~"Hispanic/Latinx",
!is.na(PRACE) ~stringr::str_replace_all(as.character(PRACE), " (and|or) ", "/") %>%
stringr::str_replace(" alone", "") %>%
stringr::str_replace(" Alone", ""))))

Summarize

rcb_re <- psrc_pums_count(rcb, group_vars = c("PRACE","rent_burden"),rr=TRUE)
rcb_re <- rcb_re %>% pivot_wider(names_from = rent_burden, values_from = c(count, count_moe, share, share_moe, reliability))

Clean table

rcb_re <- rcb_re[, c(1,3,4,5,6,8,7,9,10,11,13,12,14,15,16,18,17,24,25,26,28,27)]
rcb_re <- rcb_re[rcb_re$PRACE !='Total',]

Clean variable names

rcb_re <- rcb_re %>% rename_all(~stringr::str_replace_all(.,"count_",""))
rcb_re <- rcb_re %>% rename("No rent paid" = "NA")
rcb_re <- rcb_re %>% rename("moe_No rent paid" = "moe_NA")
rcb_re <- rcb_re %>% rename("Share_No rent paid" = "share_NA")
rcb_re <- rcb_re %>% rename("Reliability_No rent paid" = "reliability_NA")

}

Run rcb function -----------

rcb_re_all <- map(years, ~rcb_re_func(.x)) %>%
reduce(bind_rows)

graph change over time -----------

library(psrcplot)
library(ggplot2)

rcb_re_severe_cb <- static_line_chart(rcb_re_all, "DATA_YEAR", "share_Greater than 50 percent", fill = "PRACE",
title="Change in Severe Cost Burden by Race/Ethnicity (50%+ of income)",color="pgnobgy_10")
rcb_re_severe_cb`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions