Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does the cubble lose it's geometry here #19

Closed
dicook opened this issue Oct 8, 2023 · 2 comments
Closed

Why does the cubble lose it's geometry here #19

dicook opened this issue Oct 8, 2023 · 2 comments

Comments

@dicook
Copy link
Collaborator

dicook commented Oct 8, 2023

covid <- read_csv("https://raw.githubusercontent.com/numbats/eda/master/data/melb_lga_covid.csv") %>%
  mutate(Buloke = as.numeric(ifelse(Buloke == "null", "0", Buloke))) %>%
   mutate(Hindmarsh = as.numeric(ifelse(Hindmarsh == "null", "0", Hindmarsh))) %>%
   mutate(Towong = as.numeric(ifelse(Towong == "null", "0", Towong))) %>%
  pivot_longer(cols = Alpine:Yarriambiack, names_to="NAME", values_to="cases") %>%
  mutate(Date = ydm(paste0("2020/",Date))) %>%
  mutate(cases=replace_na(cases, 0))

covid <- covid %>%
  group_by(NAME) %>%
  mutate(new_cases = cases - dplyr::lag(cases)) %>%
  na.omit()

lga <- strayr::read_absmap("lga2018") |>
  rename(lga = lga_name_2018) |>
  filter(state_name_2016 == "Victoria") 

covid <- covid %>%
  select(-cases) %>%
  rename(lga = NAME, date=Date, cases = new_cases) 
covid_ts <- as_tsibble(covid, key=lga, index=date)

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

lga <- lga %>% 
  mutate(lga = ifelse(lga == "Colac-Otway (S)", "Colac Otway (S)", lga)) %>%
  filter(!(lga %in% covid_matching$others$spatial))

covid_matching <- check_key(spatial = lga, temporal = covid_ts)

covid_cb <- make_cubble(
  spatial = lga, temporal = covid_ts,
  potential_match = covid_matching, index = date)

covid_tot <- covid_cb %>%
  face_temporal() %>%
  summarise(totcases = sum(cases, na.rm = TRUE))

> covid_tot
# A tibble: 79 × 2
   lga            totcases
   <chr>             <dbl>
 1 Alpine (S)            0
 2 Ararat (RC)           2
 3 Ballarat (C)         46
 4 Banyule (C)         350
....
@dicook dicook changed the title Why does the bubble lose it's geometry here Why does the cubble lose it's geometry here Oct 8, 2023
@huizezhang-sherry
Copy link
Owner

I think what you want is covid_cb |> rowwise() |> mutate(a = sum(ts$cases, na.rm = TRUE))

@dicook
Copy link
Collaborator Author

dicook commented Oct 10, 2023

I think that it would be the correct result for

%>%
  face_temporal() %>%
  summarise(totcases = sum(cases, na.rm = TRUE))

to retain the geometry.

You need some simple examples like this in the vignettes, and also for the functions, possibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants