From 87ff5834cd9935b2d1988b5b46e657b835b4f6cc Mon Sep 17 00:00:00 2001 From: IGRiosTC Date: Wed, 12 Jul 2023 15:24:23 +0100 Subject: [PATCH] UC update to June 2023 and additional plot --- .../claimant_count_and_universal_credit.Rmd | 273 ++++++++++++----- .../claimant_count_and_universal_credit.html | 285 ++++++++++-------- 2 files changed, 345 insertions(+), 213 deletions(-) diff --git a/unemployment_covid-19/claimant_count_and_universal_credit.Rmd b/unemployment_covid-19/claimant_count_and_universal_credit.Rmd index 14a33ab..365490d 100644 --- a/unemployment_covid-19/claimant_count_and_universal_credit.Rmd +++ b/unemployment_covid-19/claimant_count_and_universal_credit.Rmd @@ -23,7 +23,7 @@ basech <- "January 2020" # URL: https://www.nomisweb.co.uk/sources/cc # Licence: Open Government Licence -cc_trafford <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1811939363&date=latestMINUS39-latest&gender=0&age=0&measure=1,2&measures=20100") %>% +cc_trafford <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1811939363&date=latestMINUS41-latest&gender=0&age=0&measure=1,2&measures=20100") %>% select(period = DATE_NAME, area_code = GEOGRAPHY_CODE, area_name = GEOGRAPHY_NAME, @@ -33,8 +33,8 @@ cc_trafford <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.dat latest <- as.character(max(as.yearmon(cc_trafford$period))) latestm12 <- as.character(max(as.yearmon(cc_trafford$period))-1) -latestch <- "April 2023" -latestm12ch <- "April 2022" +latestch <- "June 2023" +latestm12ch <- "June 2022" cc_traf <- cc_trafford %>% mutate(period=as.yearmon(period, "%b %Y"), @@ -50,7 +50,6 @@ cc_traf <- cc_trafford %>% # Claimant Count in Trafford - The [Claimant Count](https://www.nomisweb.co.uk/sources/cc) indicates the number of people claiming benefits principally for the reason of being unemployed. The Claimant Count in `r latestch` was `r filter(cc_traf,period==as.yearmon(latest, "%b %Y"))$change`% higher than in `r basech`. The rate of claimants to residents aged 16 to 64 reached `r filter(cc_traf,period==as.yearmon(latest, "%b %Y"))$rate`% in `r latestch` representing an increment of `r filter(cc_traf,period==as.yearmon(latest, "%b %Y"))$rate-cc_traf$rate[1]`% from `r basech`. The number of claimants has been decreasing from April 2021 but started to increase again from January 2023. @@ -133,48 +132,65 @@ ggplot(cc_traffordp,aes(x = date, y = round(change,0))) + -```{r CCWardData} +```{r CCMSOAData} #Claimant Count # Source: ONS # URL: https://www.nomisweb.co.uk/sources/cc # Licence: Open Government Licence + #House of Commons Library MSOA Names +# URL: https://visual.parliament.uk/msoanames +lookup <- read_csv("https://houseofcommonslibrary.github.io/msoanames/MSOA-Names-Latest.csv") %>% + filter(Laname=="Trafford") + +# Mid-2020 population estimates by ward +# Source: Nomis / ONS +# URL: https://www.nomisweb.co.uk/datasets/pestsyoaoa +# Licence: Open Government Licence 3.0 + +msoa_pop <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_2010_1.data.csv?geography=1245709510...1245709537&date=latest&gender=0&c_age=203&measures=20100") %>% + select(area_code = GEOGRAPHY_CODE, + pop16_64 = OBS_VALUE) + # claimant_ward <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1660945005...1660945019,1660945021,1660945020,1660945022...1660945025&date=latestMINUS12,latest&gender=0&age=0&measure=1,2&measures=20100") +#https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1245709510...1245709537&date=latest&gender=0&age=0&measure=1&measures=20100 -claimant_ward <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1648362073...1648362087,1648362089,1648362088,1648362090...1648362093&date=latestMINUS12,latest&gender=0&age=0&measure=1,2&measures=20100") +claimant_msoa <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1245709510...1245709537&date=latestMINUS12,latest&gender=0&age=0&measure=1&measures=20100") -claimant_area <- claimant_ward %>% +claimant_area <- claimant_msoa %>% select(period = DATE_NAME, area_code = GEOGRAPHY_CODE, - area_name = GEOGRAPHY_NAME, + area_code2 = GEOGRAPHY_NAME, measure = MEASURE_NAME, value = OBS_VALUE) %>% - mutate(period = as.yearmon(period, "%b %Y")) + mutate(period = as.yearmon(period, "%b %Y")) %>% + left_join(lookup%>%select(msoa11cd,msoa11nm,msoa11hclnm), by = c("area_code2" = "msoa11nm")) %>% + rename(area_name = msoa11hclnm) c_count <- claimant_area %>% - filter(measure=="Claimant count") %>% spread(period,value) %>% mutate(additional_claims= get(latest) - get(latestm12), `Share` = round(get(latest)/sum(get(latest)) *100,1), percentage_change = round(additional_claims/get(latestm12) *100,0)) -c_rate <- claimant_area %>% - filter(measure=="Claimants as a proportion of residents aged 16-64") %>% - spread(period,value) %>% - mutate(`Change`= get(latest)-get(latestm12)) +c_rate <- c_count %>% + left_join(msoa_pop, by="area_code") %>% + mutate(latestm12_r = round(get(latestm12)*100/pop16_64,1), latest_r=round(get(latest)*100/pop16_64,1),Change=round(latest_r-latestm12_r,1)) + ``` -The Trafford ward with the largest share of claims in `r latestch` was `r filter(c_count, Share == max(Share)) %>% pull(area_name)` with `r filter(c_count, Share == max(Share))$Share`% of all claimants within Trafford. 12 wards out of 21 have more claims in `r latestch` compared to `r latestm12ch`. `r arrange(c_count, desc(additional_claims))$area_name[1]` have the largest increase in number of claims with `r abs(arrange(c_count, desc(additional_claims))$additional_claims[1])` more, followed by `r arrange(c_count, desc(additional_claims))$area_name[2]` (`r arrange(c_count, desc(additional_claims))$additional_claims[2]`), `r arrange(c_count, desc(additional_claims))$area_name[3]` (`r arrange(c_count, desc(additional_claims))$additional_claims[3]`) and `r arrange(c_count, desc(additional_claims))$area_name[4]` (`r arrange(c_count, desc(additional_claims))$additional_claims[4]`). `r arrange(c_count, additional_claims)$area_name[1]` have the largest reduction in number of claims with `r abs(arrange(c_count, additional_claims)$additional_claims[1])` less, followed by `r arrange(c_count, additional_claims)$area_name[2]` (`r arrange(c_count, additional_claims)$additional_claims[2]`), `r arrange(c_count, additional_claims)$area_name[3]` (`r arrange(c_count, additional_claims)$additional_claims[3]`) and `r arrange(c_count, additional_claims)$area_name[4]` (`r arrange(c_count, additional_claims)$additional_claims[4]`). +The Trafford MSOA with the largest share of claims in `r latestch` was `r filter(c_count, Share == max(Share)) %>% pull(area_name)` with `r filter(c_count, Share == max(Share))$Share`% of all claimants within Trafford, almost the double of claims than Gorse Hill, the MSOA with the second largest number of claims. 8 MSOAs out of 28 have more claims in `r latestch` compared to `r latestm12ch`. `r arrange(c_count, desc(additional_claims))$area_name[1]` have the largest increase in number of claims with `r abs(arrange(c_count, desc(additional_claims))$additional_claims[1])` more, followed by `r arrange(c_count, desc(additional_claims))$area_name[2]` (`r arrange(c_count, desc(additional_claims))$additional_claims[2]`), `r arrange(c_count, desc(additional_claims))$area_name[3]` (`r arrange(c_count, desc(additional_claims))$additional_claims[3]`) and `r arrange(c_count, desc(additional_claims))$area_name[4]` (`r arrange(c_count, desc(additional_claims))$additional_claims[4]`). `r arrange(c_count, additional_claims)$area_name[1]` and `r arrange(c_count, additional_claims)$area_name[2]` have the largest reduction in number of claims with `r abs(arrange(c_count, additional_claims)$additional_claims[1])` less, followed by `r arrange(c_count, additional_claims)$area_name[3]` (`r arrange(c_count, additional_claims)$additional_claims[3]`). -```{r CCWardTable} +```{r CCMSOATable} -table2 <- c_count %>% select(area_name, latestm12_c=latestm12, latest_c=latest,additional_claims, percentage_change, Share) %>% left_join(c_rate %>% select(area_name, latestm12_r=latestm12, latest_r=latest, `Change`), by="area_name") +table2 <- c_rate %>% rename(latestm12_c=latestm12, latest_c=latest) %>% + select(-area_code2, -measure, -msoa11cd, -pop16_64, -area_code) cell_function <- function(value, colTable){ - width_neg_tot <- ifelse(min(colTable) < 0,abs(min(colTable)),0) - width_pos_tot <- ifelse(max(colTable) >= 0,max(colTable),0) + width_neg_tot <- ifelse(min(colTable, na.rm = TRUE) < 0,abs(min(colTable, na.rm = TRUE)),0) + width_pos_tot <- ifelse(max(colTable, na.rm = TRUE) >= 0,max(colTable, na.rm = TRUE),0) width_bar_tot <- width_neg_tot + width_pos_tot width_neg_percent <- paste0(width_neg_tot * 100 /width_bar_tot, "%") width_pos_percent <- paste0(width_pos_tot * 100 /width_bar_tot, "%") @@ -200,7 +216,7 @@ tbl2 <- reactable( defaultSortOrder = "asc", defaultColDef = colDef(headerClass = "header", align = "left", format = colFormat(separators = TRUE)), columns = list( - area_name = colDef(name = "Wards", align = "left"), + area_name = colDef(name = "MSOA", align = "left"), latestm12_c = colDef(name = latestm12, maxWidth = 60, align = "right"), latest_c = colDef(name = latest, maxWidth = 60, align = "right"), additional_claims = colDef( @@ -209,7 +225,7 @@ tbl2 <- reactable( cell_function(value,table2$additional_claims) } ), - Share = colDef(name = "Share Apr 23", maxWidth = 80, align = "left"), + Share = colDef(name = "Share Jun 23", maxWidth = 80, align = "left"), percentage_change = colDef(name = "% Change", maxWidth = 80, align = "right"), latestm12_r = colDef(name = latestm12, maxWidth = 60, align = "left"), latest_r = colDef(name = latest, maxWidth = 60, align = "left"), @@ -228,40 +244,50 @@ tbl2 <- reactable( ) div(class = "div", -div(class= "large-table tableTitle", "Change in the Claimant Count for Trafford's wards"), +div(class= "large-table tableTitle", "Change in the Claimant Count for Trafford's MSOAs"), tbl2 ) ``` -The wards with higher claimant rate in `r latestch` were `r arrange(table2, desc(latest_r))$area_name[1]` with `r arrange(table2, desc(latest_r))$latest_r[1]`%, `r arrange(table2, desc(latest_r))$area_name[2]` with `r arrange(table2, desc(latest_r))$latest_r[2]`%, `r arrange(table2, desc(latest_r))$area_name[3]` with `r arrange(table2, desc(latest_r))$latest_r[3]`% and `r arrange(table2, desc(latest_r))$area_name[4]` with `r arrange(table2, desc(latest_r))$latest_r[4]`%. There is a gap of 1.1% between the top five wards on claimant rate and the rest of the wards. The wards where the claimant rate has decreased more from `r latestm12ch` to `r latestch` are `r arrange(table2, Change)$area_name[1]` with a decrease in rate of `r arrange(table2, Change)$Change[1]`%, `r arrange(table2, Change)$area_name[2]` with `r arrange(table2, Change)$Change[2]`%, `r arrange(table2, Change)$area_name[3]` with `r arrange(table2, Change)$Change[3]`% followed by `r arrange(table2, Change)$area_name[4]` with `r arrange(table2, Change)$Change[4]`%. +The MSOAs with higher claimant rate in `r latestch` were `r arrange(table2, desc(latest_r))$area_name[1]` with `r arrange(table2, desc(latest_r))$latest_r[1]`%, `r arrange(table2, desc(latest_r))$area_name[2]` with `r arrange(table2, desc(latest_r))$latest_r[2]`%, `r arrange(table2, desc(latest_r))$area_name[3]` with `r arrange(table2, desc(latest_r))$latest_r[3]`% and `r arrange(table2, desc(latest_r))$area_name[4]` with `r arrange(table2, desc(latest_r))$latest_r[4]`%. From the top 4 MSOAs with the highest rates, Old Trafford is the only one with a higher rate when comparing May 2022 to May 2023. The MSOAs where the claimant rate have decreased more from `r latestm12ch` to `r latestch` are `r arrange(table2, Change)$area_name[1]` with a decrease in rate of `r arrange(table2, Change)$Change[1]`%, `r arrange(table2, Change)$area_name[2]` with `r arrange(table2, Change)$Change[2]`%, `r arrange(table2, Change)$area_name[3]` with `r arrange(table2, Change)$Change[3]`% followed by `r arrange(table2, Change)$area_name[4]` with `r arrange(table2, Change)$Change[4]`%.
-```{r CCWardDot, fig.height=6} +```{r CCMSOADot, fig.height=7} df_traff <- cc_trafford %>% mutate(period = as.yearmon(period, format="%B %Y")) %>% filter(period %in% c(as.yearmon(latest),as.yearmon(latestm12))) -df_traff_plot<- claimant_area %>% - mutate(period = as.yearmon(period, format="%b %Y")) %>% - bind_rows(df_traff) %>% - filter(measure=="Claimants as a proportion of residents aged 16-64") %>% +# df_traff_plot<- claimant_area %>% +# mutate(period = as.yearmon(period, format="%b %Y")) %>% +# bind_rows(df_traff %>% filter(measure == "")) %>% +# filter(measure=="Claimants as a proportion of residents aged 16-64") %>% +# mutate(period = factor(period, levels = c(latestm12,latest)), +# area_name = fct_reorder(factor(area_name), ifelse(period == latest, value, NA), na.rm = TRUE), +# area_name = fct_relevel(factor(area_name), "Trafford")) + +cc_plot_dot <- table2 %>% + select (area_name,{{latestm12}}:=latestm12_r, {{latest}}:=latest_r) %>% + gather(period,value,-one_of("area_name")) %>% + mutate(period=as.yearmon(period, format="%B %Y")) %>% + bind_rows(df_traff %>% filter(measure == "Claimants as a proportion of residents aged 16-64") %>% select(area_name,period,value) %>% filter(period %in% c(as.yearmon(latest),as.yearmon(latestm12))) )%>% mutate(period = factor(period, levels = c(latestm12,latest)), area_name = fct_reorder(factor(area_name), ifelse(period == latest, value, NA), na.rm = TRUE), area_name = fct_relevel(factor(area_name), "Trafford")) -ggplot(df_traff_plot, aes(value,area_name)) + + +ggplot(cc_plot_dot, aes(value,area_name)) + geom_line(color = "grey", size=1) + geom_point(aes(color = period), size = 4) + scale_x_continuous(labels = function(x){ paste0(x, "%") }, limits = c(0, 8)) + scale_colour_manual(values = c( "#66c2a4", "#006d2c")) + labs(x = "percentage of residents aged 16 to 64", y = NULL, title = "Claimant Rate", - subtitle = paste0("Trafford Wards,", latestm12, " and ", latest), + subtitle = paste0("Trafford MSOAs, ", latestm12, " and ", latest), caption = "Source: ONS")+ theme_minimal() + theme(plot.title = element_text(size=16,face = "bold"), @@ -277,13 +303,13 @@ ggplot(df_traff_plot, aes(value,area_name)) +
-```{r CCWardMap, fig.height=6} +```{r CCmsoaMap, fig.height=6} -c_rate_ward <- st_read("electoral_ward_boundaries.geojson", quiet = TRUE) %>% - left_join(., select(c_rate,latest,area_code) , by = "area_code") +c_rate_msoa <- st_read("msoa_boundaries.geojson", quiet = TRUE) %>% + left_join(., select(c_rate,latest_r,area_code) , by = "area_code") ggplot() + - geom_sf(data = c_rate_ward, aes(fill = get(latest)), alpha = 1, colour = "#FFFFFF", size = 0.5) + + geom_sf(data = c_rate_msoa, aes(fill = latest_r), alpha = 1, colour = "#FFFFFF", size = 0.5) + scale_fill_gradientn(colours = c("#edf8fb","#b2e2e2","#66c2a4","#2ca25f","#006d2c"), na.value = "#f0f0f0", guide = guide_legend(keyheight = unit(3, units = "mm"), @@ -293,7 +319,7 @@ ggplot() + title.position = 'top', nrow = 1)) + labs(x = NULL, y = NULL, title = "Claimant Rate", - subtitle = paste("Trafford, ", latest), + subtitle = paste("Trafford MSOAs, ", latest), caption = "Source: ONS\nContains OS data © Crown copyright and database right 2020") + theme(plot.margin = unit(c(0.5,0,1,0), "cm"), plot.title = element_text(size=16,face = "bold"), @@ -320,7 +346,7 @@ ggplot() + # URL: https://www.nomisweb.co.uk/sources/cc # Licence: Open Government Licence -raw_cc_age <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1811939363&date=latestMINUS39-latest&gender=0&age=0,2,10,11,3,12...16,4,17...20&measure=1&measures=20100") +raw_cc_age <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1811939363&date=latestMINUS41-latest&gender=0&age=0,2,10,11,3,12...16,4,17...20&measure=1&measures=20100") cc_age <- raw_cc_age %>% @@ -353,7 +379,7 @@ table4 <- age_bands %>% select(Age, `latestm12`= latestm12, `latest` = latest, a ``` -In Trafford from `r latestm12ch` to `r latestch` Three are bands has increased their claimant count, the age band 40-44 (45 more), 35 to 39 (40 more) and 18 to 24 (30 more). When considering the reduction of claims the age band `r filter(table3, additional_claims == min(additional_claims)) %>% pull(Age)` years had the largest reduction with `r filter(table3, additional_claims == min(additional_claims)) %>% pull(additional_claims)` less claims. +In Trafford from `r latestm12ch` to `r latestch` 5 age bands has increased the number of claimants, the age band 18 to 24 (65 more), 40 to 44 (35 more), 55 to 59 (15 more) and 30 to 34 and 16 to 17 (5 more). When considering the reduction of claims the age band `r filter(table3, additional_claims == min(additional_claims)) %>% pull(Age)` years had the largest reduction with `r filter(table3, additional_claims == min(additional_claims)) %>% pull(additional_claims)` less claims.
@@ -439,7 +465,7 @@ tbl4
-At the start of 2020 the age band 25-34 already had the highest number of claims, however after the effects of the Covid-19 pandemic which started in March 2020 this figure increased more sharply compared to the other age bands. The claimant rate as a proportion of Trafford's population within each age band showed then a higher increase in the age bands of 16-24 and 25-34 compared to the others. From January 2023 the count and rate of all age bands have increased. +At the start of 2020 the age band 25-34 already had the highest number of claims, however after the effects of the Covid-19 pandemic which started in March 2020 this figure increased more sharply compared to the other age bands. The claimant rate as a proportion of Trafford's population within each age band showed then a higher increase in the age bands of 16-24 and 25-34 compared to the others. From January 2023 the count and rate of all age bands started to increase but the figures are fluctuating from April 2023.
@@ -554,20 +580,22 @@ plotdf2 <- quinary %>%
-Almost half of Trafford's claimants are residents of five of the 21 wards. Almost half of the claimants are under 40 years. +More than half of Trafford's claimants are residents of 7 of the 28 MSOAs. More than half of the claimants are between 25 and 40 years.
-```{r CCWardAgeTable} +```{r CCMSOAAgeTable} #Claimant Count # Source: ONS # URL: https://www.nomisweb.co.uk/sources/cc # Licence: Open Government Licence -cc_ward_age <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1660945005...1660945019,1660945021,1660945020,1660945022...1660945025&date=latest&gender=0&age=10...20&measure=1&measures=20100")%>% - select(period = DATE_NAME, area_code = GEOGRAPHY_CODE, area_name = GEOGRAPHY_NAME, ageband = AGE_NAME, n = OBS_VALUE) %>% +cc_msoa_age <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.data.csv?geography=1245709510...1245709537&date=latest&gender=0&age=10...20&measure=1&measures=20100") %>% + select(period = DATE_NAME, area_code = GEOGRAPHY_CODE, area_code2 = GEOGRAPHY_NAME, ageband = AGE_NAME, n = OBS_VALUE) %>% + left_join(lookup%>%select(msoa11cd,msoa11nm,msoa11hclnm), by = c("area_code2" = "msoa11nm")) %>% + rename(area_name = msoa11hclnm) %>% mutate(period = as.Date(paste("01", period), format = "%d %b %Y"), ageband=gsub("Aged ", "", ageband)) %>% mutate(ageband = case_when( @@ -584,24 +612,24 @@ cc_ward_age <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_162_1.dat ungroup() -cc_ward_aget<- cc_ward_age %>% - select(Ward=area_name,ageband,n) %>% +cc_msoa_aget<- cc_msoa_age %>% + select(MSOA=area_name,ageband,n) %>% spread(ageband,n) tbl5 <- reactable( - cc_ward_aget, + cc_msoa_aget, pagination = FALSE, - defaultSorted = "Ward", + defaultSorted = "MSOA", defaultSortOrder = "asc", defaultColDef = colDef(headerClass = "header", align = "left", maxWidth = 45, format = colFormat(separators = TRUE)), columns = list( - Ward = colDef(maxWidth = 200, align = "left") + MSOA = colDef(maxWidth = 200, align = "left") ), - class = "small-table" + class = "xsmall-table" ) div(class = "div", -div(class= "large-table tableTitle", "Claimant Count for Trafford's wards by age band"), +div(class= "large-table tableTitle", "Claimant Count for Trafford's MSOAs by age band"), tbl5 ) @@ -611,9 +639,9 @@ tbl5
-```{r CCWardAgeMMK} +```{r CCMSOAAgeMMK, fig.height=6} -cc_ward_agep<- cc_ward_age %>% +cc_msoa_agep<- cc_msoa_age %>% spread(ageband,n) %>% mutate("16-24" = `16-17`+`18-24`) %>% select(period:area_name,`16-24`,`25-34`:`65+`) %>% @@ -622,14 +650,25 @@ cc_ward_agep<- cc_ward_age %>% mutate(ageband = fct_rev(ageband), total = sum(n), percent = n/total) -ggplot(cc_ward_agep, aes(x = area_name, y = percent, width = total, fill = ageband)) + +stats <- cc_msoa_agep %>% + summarise(totalm =sum(n)) %>% + ungroup() %>% + mutate(perM = totalm*100/sum(totalm)) + +stats2 <- cc_msoa_agep %>% + ungroup() %>% + group_by(period, ageband) %>% + summarise(totalm =sum(n)) %>% + mutate(perM = totalm*100/sum(totalm)) + +ggplot(cc_msoa_agep, aes(x = area_name, y = percent, width = total, fill = ageband)) + geom_col(position = "stack", colour = NA) + facet_grid(~fct_reorder(area_name,total, .desc = T), scales = "free_x", space = "free_x") + scale_y_continuous(expand = c(0.005, 0.005), breaks = c(0, 0.5, 1), labels = percent) + scale_fill_brewer(palette = "Set3") + labs(x = NULL, y = NULL, - title = "Claimant Count by Trafford's Wards and age band", - subtitle = as.yearmon(unique(cc_ward_agep$period)), + title = "Claimant Count by Trafford's MSOAs and age band", + subtitle = as.yearmon(unique(cc_msoa_agep$period)), caption = "The width of the columns is proportional to the number of claimants. Source: DWP.", fill = NULL) + theme(plot.title = element_text(size=16,face = "bold"), @@ -683,7 +722,7 @@ query <- list(database = unbox("str:database:UC_Monthly"), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE` = list( map = list("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE:V_C_MASTERGEOG11_LA_TO_REGION:E08000009")), `str:field:UC_Monthly:F_UC_DATE:DATE_NAME` = list( - map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202101,202102,202103,202104,202105,202106,202107,202108,202109,202110,202111,202112,202201,202202,202203,202204,202205,202206,202207,202208,202209,202210,202211,202212,202301,202302,202303,202304)))) + map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202101,202102,202103,202104,202105,202106,202107,202108,202109,202110,202111,202112,202201,202202,202203,202204,202205,202206,202207,202208,202209,202210,202211,202212,202301,202302,202303,202304,202305,202306)))) )) %>% toJSON() request <- POST( url = path, @@ -789,19 +828,8 @@ ggplot(uc_plot_ch,aes(x = date, y = change)) + ```{r UCMSOATableData} - #House of Commons Library MSOA Names -# URL: https://visual.parliament.uk/msoanames -lookup <- read_csv("https://houseofcommonslibrary.github.io/msoanames/MSOA-Names-Latest.csv") %>% - filter(Laname=="Trafford") -# Mid-2019 population estimates by ward -# Source: Nomis / ONS -# URL: https://www.nomisweb.co.uk/datasets/pestsyoaoa -# Licence: Open Government Licence 3.0 -msoa_pop <- read_csv("https://www.nomisweb.co.uk/api/v01/dataset/NM_2010_1.data.csv?geography=1245709510...1245709537&date=latest&gender=0&c_age=203&measures=20100") %>% - select(area_code = GEOGRAPHY_CODE, - pop16_64 = OBS_VALUE) #Universal Credit # Source: DWP @@ -817,7 +845,7 @@ query <- list(database = unbox("str:database:UC_Monthly"), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE` = list( map = as.list(paste0("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE:V_C_MASTERGEOG11_MSOA_TO_LA:E0", seq(2001259, 2001286, 1)))), `str:field:UC_Monthly:F_UC_DATE:DATE_NAME` = list( - map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202204,202304)))) + map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202206,202306)))) )) %>% toJSON() request <- POST( url = path, @@ -844,13 +872,12 @@ uc <- as.data.frame.table(values, stringsAsFactors = FALSE) %>% left_join(msoa_pop, by="area_code") %>% mutate(latestm12_rate = round(get(latestm12)*100/pop16_64,1), latest_rate=round(get(latest)*100/pop16_64,1),Change=round(latest_rate-latestm12_rate,1)) - table7 <- uc %>% select(-c(area_code,pop16_64)) ``` -The Trafford MSOA with the largest share of claims in `r latestch` was `r filter(table7, Share == max(Share)) %>% pull(area_name)` with `r filter(table7, Share == max(Share))$Share`% of all Universal Credit claims in Trafford. 24 out of the 28 MSOAs have more claims in `r latestch` compared to `r latestm12ch`. The MSOAs with more additional claims when comparing `r latestm12ch` to `r latestch` were `r arrange(table7,desc(additional_claims))$area_name[1]` (`r arrange(table7,desc(additional_claims))$additional_claims[1]`), `r arrange(table7,desc(additional_claims))$area_name[2]` (`r arrange(table7, desc(additional_claims))$additional_claims[2]`) and `r arrange(table7, desc(additional_claims))$area_name[3]` (`r arrange(table7,desc(additional_claims))$additional_claims[3]`). The MSOAs with more increase in percentage change from `r latestm12ch` to `r latestch` were `r arrange(table7, desc(percentage_change))$area_name[1]` and `r arrange(table7, desc(percentage_change))$area_name[2]` with `r arrange(table7, desc(percentage_change))$percentage_change[1]`% change. The MSOAs with reductions in claims when comparing `r latestm12ch` to `r latestch` are `r arrange(table7,additional_claims)$area_name[1]` (`r arrange(table7,additional_claims)$additional_claims[1]`), `r arrange(table7,additional_claims)$area_name[2]` (`r arrange(table7, additional_claims)$additional_claims[2]`) and `r arrange(table7,additional_claims)$area_name[3]` (`r arrange(table7, additional_claims)$additional_claims[3]`). The MSOAs with more increase in percentage change from `r latestm12ch` to `r latestch` were `r arrange(table7, desc(percentage_change))$area_name[1]` and `r arrange(table7, desc(percentage_change))$area_name[2]` with `r arrange(table7, desc(percentage_change))$percentage_change[1]`% change. +The Trafford MSOA with the largest share of claims in `r latestch` was `r filter(table7, Share == max(Share)) %>% pull(area_name)` with `r filter(table7, Share == max(Share))$Share`% of all Universal Credit claims in Trafford. 24 out of the 28 MSOAs have more claims in `r latestch` compared to `r latestm12ch`. The MSOAs with more additional claims when comparing `r latestm12ch` to `r latestch` were `r arrange(table7,desc(additional_claims))$area_name[1]` (`r arrange(table7,desc(additional_claims))$additional_claims[1]`), `r arrange(table7,desc(additional_claims))$area_name[2]` (`r arrange(table7, desc(additional_claims))$additional_claims[2]`) and `r arrange(table7, desc(additional_claims))$area_name[3]` (`r arrange(table7,desc(additional_claims))$additional_claims[3]`). The MSOAs with more increase in percentage change from `r latestm12ch` to `r latestch` were `r arrange(table7, desc(percentage_change))$area_name[1]` with `r arrange(table7, desc(percentage_change))$percentage_change[1]`% change, followed by `r arrange(table7, desc(percentage_change))$area_name[2]` with `r arrange(table7, desc(percentage_change))$percentage_change[2]`% change. The MSOAs with reductions in claims when comparing `r latestm12ch` to `r latestch` are `r arrange(table7,additional_claims)$area_name[1]` (`r arrange(table7,additional_claims)$additional_claims[1]`), `r arrange(table7,additional_claims)$area_name[2]` (`r arrange(table7, additional_claims)$additional_claims[2]`) and `r arrange(table7,additional_claims)$area_name[3]` (`r arrange(table7, additional_claims)$additional_claims[3]`). The MSOAs with reduction in percentage change from `r latestm12ch` to `r latestch` were `r arrange(table7, percentage_change)$area_name[1]` with `r arrange(table7, percentage_change)$percentage_change[1]`% change, followed by `r arrange(table7, percentage_change)$area_name[3]` and `r arrange(table7, percentage_change)$area_name[2]` with `r arrange(table7, percentage_change)$percentage_change[2]`%. ```{r UCMSOATable} @@ -874,7 +901,7 @@ tbl7 <- reactable( } ), percentage_change = colDef(name = "% Change", maxWidth = 80), - Share = colDef(name = "Share Apr 23", maxWidth = 80, align = "left"), + Share = colDef(name = "Share Jun 23", maxWidth = 80, align = "left"), latestm12_rate = colDef(name = latestm12, maxWidth = 60, align = "left"), latest_rate = colDef(name = latest, maxWidth = 60, align = "left"), `Change` = colDef( @@ -899,12 +926,12 @@ tbl7 ``` -The MSOAs with higher rates of Universal Credit claims in `r latestch` were `r filter(table7, latest_rate == max(latest_rate)) %>% pull(area_name)` with `r filter(table7, latest_rate == max(latest_rate))$latest_rate`% and `r arrange(table7, desc(latest_rate))$area_name[2]` with `r arrange(table7, desc(latest_rate))$latest_rate[2]`%. The MSOAs where the rate of Universal Credit claims has increased more from `r latestm12ch` to `r latestch` were `r arrange(table7, desc(Change))$area_name[1]` with `r arrange(table7, desc(Change))$Change[1]`% and `r arrange(table7, desc(Change))$area_name[2]` with `r arrange(table7, desc(Change))$Change[2]`% decrease. The MSOA where the rate of Universal Credit claims has decreased more from `r latestm12ch` to `r latestch` was `r arrange(table7, Change)$area_name[1]` with `r arrange(table7, Change)$Change[1]`% and and `r arrange(table7, Change)$area_name[2]` with `r arrange(table7, Change)$Change[2]`%. +The MSOAs with higher rates of Universal Credit claims in `r latestch` were `r filter(table7, latest_rate == max(latest_rate)) %>% pull(area_name)` with `r filter(table7, latest_rate == max(latest_rate))$latest_rate`% and `r arrange(table7, desc(latest_rate))$area_name[2]` with `r arrange(table7, desc(latest_rate))$latest_rate[2]`%. The MSOAs where the rate of Universal Credit claims has increased more from `r latestm12ch` to `r latestch` were `r arrange(table7, desc(Change))$area_name[1]` with `r arrange(table7, desc(Change))$Change[1]`% and `r arrange(table7, desc(Change))$area_name[2]` with `r arrange(table7, desc(Change))$Change[2]`% increase. The MSOA where the rate of Universal Credit claims has decreased more from `r latestm12ch` to `r latestch` was `r arrange(table7, Change)$area_name[1]` with `r arrange(table7, Change)$Change[1]`%, `r arrange(table7, Change)$area_name[2]` with `r arrange(table7, Change)$Change[2]`%, and `r arrange(table7, Change)$area_name[3]` with `r arrange(table7, Change)$Change[3]`%.
-```{r UCMSOADotPlot, fig.height=6} +```{r UCMSOADotPlot, fig.height=7} uc_plot_dot <- table7 %>% select (area_name,{{latestm12}}:=latestm12_rate, {{latest}}:=latest_rate) %>% @@ -991,7 +1018,7 @@ query <- list(database = unbox("str:database:UC_Monthly"), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE` = list( map = list("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE:V_C_MASTERGEOG11_LA_TO_REGION:E08000009")), `str:field:UC_Monthly:F_UC_DATE:DATE_NAME` = list( - map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202101,202102,202103,202104,202105,202106,202107,202108,202109,202110,202111,202112,202201,202202,202203,202204,202205,202206,202207,202208,202210,202211,202212,202301,202302,202303,202304)))), + map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202101,202102,202103,202104,202105,202106,202107,202108,202109,202110,202111,202112,202201,202202,202203,202204,202205,202206,202207,202208,202210,202211,202212,202301,202302,202303,202304,202305,202306)))), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:AGE_CODE` = list( map = as.list(paste0("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:AGE_CODE:C_UC_AGE_BAND:",c(1,2,3,4,5,6,7,8,9,10,999)))) @@ -1024,10 +1051,11 @@ table8 <- traf_uc %>% select(Age, `latestm12`= latestm12, `latest` = latest, additional_claims, percentage_change) ``` -In Trafford from `r latestm12ch` to `r latestch` the `r filter(table8, percentage_change == max(percentage_change)) %>% pull(Age)` age band has the largest increment in percentage change of Universal Credit claims with `r filter(table8, percentage_change == max(percentage_change)) %>% pull(percentage_change)`%. When considering the number of additional claims from `r latestm12ch` to `r latestch` the 5-year age band `r filter(table8, additional_claims == max(additional_claims)) %>% pull(Age)` years had the highest with `r filter(table8, additional_claims == max(additional_claims)) %>% pull(additional_claims)` more claims. The age bands `r arrange(table8, additional_claims)$Age[1]` and `r arrange(table8, additional_claims)$Age[2]` have the largest decrease in number of Universal Credit claims. Claimants under 30 decreased in number whilst claimants 30 and over increased in number when comparing `r latestm12ch` to `r latestch`. +In Trafford from `r latestm12ch` to `r latestch` the `r filter(table8, percentage_change == max(percentage_change)) %>% pull(Age)` age band has the largest increment in percentage change of Universal Credit claims with `r filter(table8, percentage_change == max(percentage_change)) %>% pull(percentage_change)`%. When considering the number of additional claims from `r latestm12ch` to `r latestch` the 5-year age band `r filter(table8, additional_claims == max(additional_claims)) %>% pull(Age)` years had the highest with `r filter(table8, additional_claims == max(additional_claims)) %>% pull(additional_claims)` more claims. All age bands had an increment of claims compared to `r latestm12ch`. ```{r UCAgeTable} +#The age bands `r arrange(table8, additional_claims)$Age[1]` and `r arrange(table8, additional_claims)$Age[2]` have the largest decrease in number of Universal Credit claims. Claimants under 30 decreased or not changed in number whilst claimants 30 and over increased in number when comparing `r latestm12ch` to `r latestch`. tbl8 <- reactable( table8, @@ -1187,7 +1215,7 @@ query <- list(database = unbox("str:database:UC_Monthly"), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE` = list( map = as.list(paste0("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE:V_C_MASTERGEOG11_MSOA_TO_LA:E0", seq(2001259, 2001286, 1)))), `str:field:UC_Monthly:F_UC_DATE:DATE_NAME` = list( - map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202304)))), + map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202306)))), `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:CCCONDITIONALITY_REGIME` = list( map = as.list(paste0("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:CCCONDITIONALITY_REGIME:C_UC_CONDITIONALITY_REGIME:",c("AA","AB","BC","BD","DF","CE")))) @@ -1212,7 +1240,7 @@ uc_condition <- as.data.frame.table(values, stringsAsFactors = FALSE) %>% ``` -The [Conditionality](https://stat-xplore.dwp.gov.uk/webapi/metadata/UC_Monthly/Conditionality%20Regime.html) regimen for entitlement to Universal Credit is associated to work-related things that claimants will have to do to maintain elegibility. In Trafford the largest proportion of Universal Credit claims are in the "No work requirements" category however there is also a significant proportion of claims under "Searching for work". +The [Conditionality](https://stat-xplore.dwp.gov.uk/webapi/metadata/UC_Monthly/Conditionality%20Regime.html) regimen for entitlement to Universal Credit is associated to work-related things that claimants will have to do to maintain eligibility. In Trafford the largest proportion of Universal Credit claims are in the "No work requirements" category however there is also a significant proportion of claims under "Searching for work". In Old Trafford, 33% of Universal Credit claimants were under "No work requirements" whilst 31% where "Searching for work". In Partington, 43% of claims were under "No work requirements" whilst 20% of claims were under "Searching for work" and "Working - no requirements" each. ```{r UCConditionMMK, fig.height=5.5,fig.width=7} uc_msoa_cond<- uc_condition %>% @@ -1243,8 +1271,91 @@ ggplot(uc_msoa_cond, aes(x = area_name, y = percent, width = total, fill = condi ``` -
-
+ + +```{r UCConditionDataTrend} + +#Universal Credit +# Source: DWP +# URL: https://stat-xplore.dwp.gov.uk/webapi/metadata/UC_Monthly/UC_Monthly.html +# Licence: Open Government Licence + +query <- list(database = unbox("str:database:UC_Monthly"), + measures = "str:count:UC_Monthly:V_F_UC_CASELOAD_FULL", + dimensions = c("str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE", + "str:field:UC_Monthly:F_UC_DATE:DATE_NAME", + "str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:CCCONDITIONALITY_REGIME") %>% matrix(), + recodes = list( + `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE` = list( + map = list("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:COA_CODE:V_C_MASTERGEOG11_LA_TO_REGION:E08000009")), + `str:field:UC_Monthly:F_UC_DATE:DATE_NAME` = list( + map = as.list(paste0("str:value:UC_Monthly:F_UC_DATE:DATE_NAME:C_UC_DATE:",c(202001,202002,202003,202004,202005,202006,202007,202008,202009,202010,202011,202012,202101,202102,202103,202104,202105,202106,202107,202108,202109,202110,202111,202112,202201,202202,202203,202204,202205,202206,202207,202208,202210,202211,202212,202301,202302,202303,202304,202305,202306)))), + `str:field:UC_Monthly:V_F_UC_CASELOAD_FULL:CCCONDITIONALITY_REGIME` = list( + map = as.list(paste0("str:value:UC_Monthly:V_F_UC_CASELOAD_FULL:CCCONDITIONALITY_REGIME:C_UC_CONDITIONALITY_REGIME:",c("AA","AB","BC","BD","DF","CE")))) + + )) %>% toJSON() +request <- POST( + url = path, + body = query, + config = add_headers(APIKey = api_key), + encode = "json") + +response <- fromJSON(content(request, as = "text"), flatten = TRUE) +# extract list items and convert to a dataframe +tabnames <- response$fields$items %>% map(~.$labels %>% unlist) +values <- response$cubes[[1]]$values +dimnames(values) <- tabnames + +uc_condition_trend <- as.data.frame.table(values, stringsAsFactors = FALSE) %>% + as_tibble() %>% + set_names(c(response$fields$label,"value")) %>% + mutate(period=format(as.yearmon(`Month`, "%B %Y"),"%b %Y")) %>% + select(area_name = "National - Regional - LA - OAs", condition = `Conditionality Regime`, period, value) %>% + group_by(period) %>% + mutate(Percent = round(value *100/sum(value),1)) %>% + ungroup() + +``` + +Claimants continue to move across from legacy benefits to Universal credit therefore, the number of claimants with no work requirements continue to grow. In `r latestch`, `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[1]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[1]`) of claims in Trafford were under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[1]`", `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[2]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[2]`) were under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[2]`", `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[3]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[3]`) were under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[3]`", `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[4]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[4]`) were under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[4]`", `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[5]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[5]`) were under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[5]`", and `r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$Percent[6]`% (`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$value[6]`) where under "`r (uc_condition_trend %>%filter(period == latest) %>% arrange(desc(Percent)))$condition[6]`". +
+
+ +```{r UCConditionalityLine, fig.height=3.5, fig.width=7} + +uc_plot_conditionality_c <- uc_condition_trend %>% + mutate(date=as.Date(as.yearmon(period), format="%b %Y")) %>% + mutate(condition = fct_rev(condition)) + + + ggplot(uc_plot_conditionality_c , aes(x = date, y = value, colour = condition)) + + geom_hline(yintercept = 0, size = 0.3, colour = "#333333") + + geom_line(size = 1) + + #geom_text_repel(aes(x = max(date) + 60, label = label, fontface = "bold", hjust = 1), direction = "y", show.legend = FALSE) + + #scale_color_startrek() + + scale_color_brewer(palette = "Set3") + + scale_x_date(breaks = c(min(uc_plot_conditionality_c$date), as.Date(as.yearmon("Apr 2020"),format="%b %Y"), as.Date(as.yearmon("Jan 2021"),format="%b %Y"), as.Date(as.yearmon("Jan 2022"),format="%b %Y"), max(uc_plot_conditionality_c$date)), date_labels = "%b %y") + + scale_y_continuous(expand = c(0.005, 0.005)) + + labs(title = "Univeral Credit claims by conditionality", + subtitle = paste("Trafford, ", base, " - ",latest), + caption = "Source: DWP", + x = NULL, + y = NULL, + colour = NULL) + + theme_minimal(base_size = 10) + + theme(plot.title = element_text(size=12,face = "bold"), + plot.subtitle = element_text(size=10), + plot.margin = unit(rep(0.5,4), "cm"), + panel.grid.major.x = element_blank(), + panel.grid.minor = element_blank(), + axis.ticks.x = element_line(colour = "#333333", size = 0.5)) + + coord_cartesian(clip = "off") + +``` + +
+
+ @@ -1342,13 +1453,17 @@ p { font-size: 12px; } -.small-table { +.small-table, .xsmall-table { font-size: 11px; } .small-table .rt-td { padding: 3px 3px; } +.xsmall-table .rt-td .rt-td-inner{ + padding: 0px 0px; + font-size: 11px; +} .large-table .rt-td { white-space: nowrap; diff --git a/unemployment_covid-19/claimant_count_and_universal_credit.html b/unemployment_covid-19/claimant_count_and_universal_credit.html index 08c674a..f17d007 100644 --- a/unemployment_covid-19/claimant_count_and_universal_credit.html +++ b/unemployment_covid-19/claimant_count_and_universal_credit.html @@ -1350,20 +1350,18 @@ document.body.style.height = "100%"; document.documentElement.style.width = "100%"; document.documentElement.style.height = "100%"; - if (cel) { - cel.style.position = "absolute"; - var pad = unpackPadding(sizing.padding); - cel.style.top = pad.top + "px"; - cel.style.right = pad.right + "px"; - cel.style.bottom = pad.bottom + "px"; - cel.style.left = pad.left + "px"; - el.style.width = "100%"; - el.style.height = "100%"; - } + cel.style.position = "absolute"; + var pad = unpackPadding(sizing.padding); + cel.style.top = pad.top + "px"; + cel.style.right = pad.right + "px"; + cel.style.bottom = pad.bottom + "px"; + cel.style.left = pad.left + "px"; + el.style.width = "100%"; + el.style.height = "100%"; return { - getWidth: function() { return cel.offsetWidth; }, - getHeight: function() { return cel.offsetHeight; } + getWidth: function() { return cel.getBoundingClientRect().width; }, + getHeight: function() { return cel.getBoundingClientRect().height; } }; } else { @@ -1371,8 +1369,8 @@ el.style.height = px(sizing.height); return { - getWidth: function() { return el.offsetWidth; }, - getHeight: function() { return el.offsetHeight; } + getWidth: function() { return cel.getBoundingClientRect().width; }, + getHeight: function() { return cel.getBoundingClientRect().height; } }; } } @@ -1596,8 +1594,8 @@ elementData(el, "initialized", true); if (bindingDef.initialize) { - var result = bindingDef.initialize(el, el.offsetWidth, - el.offsetHeight); + var rect = el.getBoundingClientRect(); + var result = bindingDef.initialize(el, rect.width, rect.height); elementData(el, "init_result", result); } } @@ -1639,29 +1637,30 @@ forEach(matches, function(el) { var sizeObj = initSizing(el, binding); + var getSize = function(el) { + if (sizeObj) { + return {w: sizeObj.getWidth(), h: sizeObj.getHeight()} + } else { + var rect = el.getBoundingClientRect(); + return {w: rect.width, h: rect.height} + } + }; + if (hasClass(el, "html-widget-static-bound")) return; el.className = el.className + " html-widget-static-bound"; var initResult; if (binding.initialize) { - initResult = binding.initialize(el, - sizeObj ? sizeObj.getWidth() : el.offsetWidth, - sizeObj ? sizeObj.getHeight() : el.offsetHeight - ); + var size = getSize(el); + initResult = binding.initialize(el, size.w, size.h); elementData(el, "init_result", initResult); } if (binding.resize) { - var lastSize = { - w: sizeObj ? sizeObj.getWidth() : el.offsetWidth, - h: sizeObj ? sizeObj.getHeight() : el.offsetHeight - }; + var lastSize = getSize(el); var resizeHandler = function(e) { - var size = { - w: sizeObj ? sizeObj.getWidth() : el.offsetWidth, - h: sizeObj ? sizeObj.getHeight() : el.offsetHeight - }; + var size = getSize(el); if (size.w === 0 && size.h === 0) return; if (size.w === lastSize.w && size.h === lastSize.h) @@ -1963,14 +1962,9 @@ return result; } })(); - -
+