history <- longunread%>% dplyr::group_by( Period ) %>% dplyr::summarise( Meters_unread = sum(Meters_Unread_in_12mo), total = sum(TotalMeters), percent_unread = sum(Meters_Unread_in_12mo)/sum(TotalMeters) ) %>% dplyr::filter( Period > "2019-03-01" ) forecast <- lm(percent_unread~Period, data = history[(nrow(history)-4):nrow(history),]) predict <- data.frame( Period = c( max(history$Period)%m+%months(1), max(history$Period)%m+%months(2), max(history$Period)%m+%months(3) ) ) predict$percent_unread_forecast <- predict.lm(forecast, predict) history_w_forecast <- dplyr::bind_rows(history, predict) history_w_forecast$percent_unread_forecast[history_w_forecast$Period==max(history$Period)] <- history_w_forecast$percent_unread[history_w_forecast$Period==max(history$Period)] ggplot2::ggplot(history_w_forecast, ggplot2::aes(x = Period)) + ggplot2::geom_bar(ggplot2::aes(x = Period, y = Meters_unread), stat = "identity", position = "dodge", inherit.aes = FALSE,fill = "#005F83") + ggplot2::geom_line(ggplot2::aes(y = percent_unread_forecast*(1.05*max(history_w_forecast$total, na.rm = TRUE)), colour = "Forecast"), size = 1.4) + ggplot2::geom_point(ggplot2::aes(y = percent_unread_forecast*(1.05*max(history_w_forecast$total, na.rm = TRUE)), colour = "Forecast"), size=3) + ggplot2::geom_line(ggplot2::aes(y = percent_unread*(1.05*max(history_w_forecast$total, na.rm = TRUE)), colour = "Observed"), size = 1.4) + ggplot2::geom_point(ggplot2::aes(y = percent_unread * (1.05 * max(history_w_forecast$total, na.rm = TRUE)), colour = "Observed"), size = 3) + ggplot2::scale_y_continuous( label = scales::unit_format(accuracy = 1, unit = "", sep = "", big.mark = ","), breaks = scales::pretty_breaks(4), sec.axis = ggplot2::sec_axis( ~. / (1.05*max(history_w_forecast$total, na.rm = TRUE)), name = "Percentage of meters unread", labels = scales::percent_format(accuracy = 1) ), limits = c( min(history_w_forecast$Meters_unread,na.rm = TRUE) - 40000, max(history_w_forecast$Meters_unread, na.rm = TRUE) + 30000), oob = scales::rescale_none ) + ggplot2::scale_color_manual(values = c("#FFAA4D", "#00A499")) + ggplot2::ylab("Total number of meters unread") + ggplot2::ggtitle("Meters Unread for 12+ months") + ggplot2::theme_bw()+ ggplot2::theme( plot.title = ggplot2::element_text(hjust = 0.5), legend.title = ggplot2::element_blank(), legend.position = "bottom", axis.title.x = ggplot2::element_blank() )
This chart shows the change in volume (bars) and % (line) of meters unread for at least 12 months, with a forecast for the next 3 months
\ \
\newpage
history_MO <- longunread %>% dplyr::group_by(Period) %>% dplyr::summarise( Meters_Unread_Since_MO = sum(Meters_Unread_Since_MO), total = sum(TotalMeters), percent_unread_MO = sum(Meters_Unread_Since_MO) / sum(TotalMeters) ) %>% dplyr::filter(Period > "2019-03-01") forecast_MO <- lm(percent_unread_MO ~ Period, data = history_MO[(nrow(history_MO)-4):nrow(history_MO),]) predict_MO <- data.frame( Period = c( max(history_MO$Period) %m+% months(1), max(history_MO$Period) %m+% months(2), max(history_MO$Period) %m+% months(3) ) ) predict_MO$percent_unread_MO_forecast <- predict.lm(forecast_MO, predict_MO) history_MO_w_forecast <- dplyr::bind_rows(history_MO, predict_MO) history_MO_w_forecast$percent_unread_MO_forecast[history_MO_w_forecast$Period==max(history$Period)] <- history_MO_w_forecast$percent_unread_MO[history_MO_w_forecast$Period==max(history$Period)] ggplot2::ggplot( history_MO_w_forecast, ggplot2::aes( x = Period ) )+ ggplot2::geom_bar( ggplot2::aes( x=Period, y = Meters_Unread_Since_MO ), stat = "identity", position = "dodge", inherit.aes = FALSE, fill = "#005F83" )+ ggplot2::geom_line( ggplot2::aes( y = percent_unread_MO_forecast*(1.05*max(history_w_forecast$total, na.rm = TRUE)), color="Forecast" ), size=1.4 )+ ggplot2::geom_point( ggplot2::aes( y = percent_unread_MO_forecast*(1.05*max(history_w_forecast$total, na.rm = TRUE)), color="Forecast" ), size=3 )+ ggplot2::geom_line( ggplot2::aes( y = percent_unread_MO*(1.05*max(history_w_forecast$total, na.rm = TRUE)), color="Observed" ), size=1.4 )+ ggplot2::geom_point( ggplot2::aes( y = percent_unread_MO*(1.05*max(history_w_forecast$total, na.rm = TRUE)), color="Observed" ), size=3 )+ ggplot2::scale_y_continuous( label = scales::unit_format(accuracy = 1, unit = "", sep = "", big.mark = ","), breaks = scales::pretty_breaks(4), sec.axis = ggplot2::sec_axis( ~. / (1.1*max(history_MO_w_forecast$total, na.rm = TRUE)), name = "Percentage of meters unread", labels = scales::percent_format(accuracy = 1) ), oob = scales::rescale_none )+ ggplot2::scale_color_manual(values = c("#FFAA4D", "#00A499"))+ ggplot2::ylab( "Total number of meters unread" )+ ggplot2::ggtitle( "Meters Unread since Market Opening" )+ ggplot2::theme_bw()+ ggplot2::theme( plot.title = ggplot2::element_text( hjust = 0.5 ), legend.title = ggplot2::element_blank(), legend.position = "bottom", axis.title.x = ggplot2::element_blank() )
This chart shows the change in volume (bars) and % (line) of meters unread for at least 12 months, with a forecast for the next 3 months
\
\
\newpage
\blandscape
longunread_avg <- longunread %>% dplyr::filter(Period == max(longunread$Period)) %>% dplyr::summarise(Total = sum(Meters_Unread_in_12mo) / sum(TotalMeters)) graph_data <- MOSLR::MPOP_data_prep( df.longunread = longunread, tp.details = tp_details, longunread.table = TRUE, by = "Retailer", my.dir = my_dir ) MOSLR::bubble_chart( df = graph_data, longunread.graph = TRUE, by = "Retailer", vertical.sep = longunread_avg$Total ) # arrow = ggplot2::arrow(angle = 10, type = "closed") # # graph <- ggplot2::ggplot(main, ggplot2::aes(x = percent, y = change, label = ShortName)) + # ggplot2::geom_rect(xmin = -vertical.sep, xmax = Inf,ymin = 0,ymax = Inf,fill = "#C6E0B4",alpha = 0.1) + # ggplot2::geom_rect(xmin = -Inf,xmax = -vertical.sep,ymin = 0,ymax = Inf,fill = "#FFE699",alpha = 0.1) + # ggplot2::geom_rect(xmin = -vertical.sep,xmax = Inf,ymin = -Inf,ymax = 0,fill = "#FFE699",alpha = 0.1) + # ggplot2::geom_rect(xmin = -Inf,xmax = -vertical.sep,ymin = -Inf,ymax = 0,fill = "#F08080",alpha = 0.1) + # ggplot2::geom_point(ggplot2::aes(size = TotalMeters,fill = `Change in size`),pch = 21) + # ggrepel::geom_text_repel(size = 2.5,fontface = "bold") + # ggplot2::annotate(geom = "label",x = -0.035,y = -max(abs(main$change)),label = "Leading",fill = "azure2") + # ggplot2::annotate(geom = "label",x = 2 * (vertical.sep + 0.015),y = -max(abs(main$change)),label = "Improving",fill = "azure2") + # ggplot2::annotate(geom = "label",x = -0.04,y = max(abs(main$change)),label = "At risk",fill = "azure2") + # ggplot2::annotate(geom = "label", x = 2 * (vertical.sep + 0.015), y = max(abs(main$change)), label = "Declining", fill = "azure2") + # ggplot2::scale_x_reverse(labels = scales::percent_format(accuracy = 1), limits = c(2 * (vertical.sep + 0.02), -0.04)) + # ggplot2::scale_y_reverse(labels = scales::percent_format(accuracy = 1), limits = c(max(abs(main$change)), -max(abs(main$change)))) + # ggplot2::xlab("Total % of meters not read within past 12 months") + # ggplot2::ylab("Change in % of unread meters in the last 12 months") + # ggplot2::ggtitle(title) + # ggplot2::theme_classic() + # ggplot2::theme( # axis.text = ggplot2::element_text(size = 9, face = "bold"),axis.title = ggplot2::element_text(size = 9,face = "bold"), # axis.line = ggplot2::element_line(arrow = arrow), # title = ggplot2::element_text(size = 9, face = "bold"), # plot.title = ggplot2::element_text(hjust = 0.5), # legend.position = "bottom", # legend.title = ggplot2::element_text(size = 12,face = "bold"), # legend.text = ggplot2::element_text(size = 8) # ) + # ggplot2::scale_size_continuous(range = c(2, 20)) + # ggplot2::scale_fill_manual(values = c("#05C3DE", "#005F83", "#CDCDCD")) + # ggplot2::guides(size = FALSE, fill = ggplot2::guide_legend(override.aes = list(size = 7)))
This chart shows relative volumes of Long Unread meters by Retailers and their movement over the past 12 months.
\newpage \elandscape \arrayrulecolor{black}
top10_long_ret <- graph_data %>% dplyr::mutate( percent_temp = ifelse( percent - last_percent > 0, paste0(round(percent*100, 1), "\\% $\\uparrow$"), paste0(round(percent*100, 1), "\\% $\\downarrow$") ), percent_temp = kableExtra::cell_spec( percent_temp, "latex", background = dplyr::case_when( percent > longunread_avg$Total ~ "#F08080", percent>0.05 & percent < longunread_avg$Total ~ "#FFe699", percent < 0.05 ~ "#C6E0B4", TRUE ~ "#FFFFFF"), escape = FALSE), TotalMeters = scales::comma(TotalMeters, digits = 0), PureLUMs = scales::comma(PureLUMs, digits = 0) ) %>% dplyr::arrange(dplyr::desc(percent)) %>% dplyr::select(Retailer, TotalMeters, PureLUMs, percent_temp) knitr::kable( top10_long_ret, format = "latex", col.names = c("Retailer", "Total number of meters", "Number of Long unread meters", "Percentage of Long unread meters"), booktabs = TRUE, escape = FALSE, linesep = "", caption = "Retailer Long unread ranking", align = c("l", rep("r", ncol(top10_long_ret)-1))) %>% kableExtra::kable_styling(latex_options = c("hold_position", "striped", "scale_down")) %>% kableExtra::row_spec(1:nrow(top10_long_ret), hline_after = TRUE)
\arrayrulecolor{white}
knitr::kable( table_legend_long, "latex", booktabs = TRUE, col.names = c("", " ", " "), linesep = "", escape = FALSE ) %>% kableExtra::kable_styling(latex_options = c("hold_position", "scale_down"))
\arrayrulecolor{black}
Only Retailers with more than 100 meters are included here.
The arrows indicate the change in percentage of Long Unread meters compared to last month
\newpage \blandscape
graph_data <- MOSLR::MPOP_data_prep(df.longunread = longunread, tp.details = tp_details, longunread.table = TRUE, by = "Wholesaler", my.dir = my_dir) MOSLR::bubble_chart(df = graph_data, longunread.graph = TRUE, by = "Wholesaler", vertical.sep = longunread_avg$Total)
This chart shows relative volumes of Long Unread meters by Wholesaler area and their movement over the past 12 months.
\newpage \elandscape
top10_long_whole <- graph_data%>% dplyr::mutate( percent_temp = ifelse( percent - last_percent > 0, paste0(round(percent*100, 1), "\\% $\\uparrow$"), paste0(round(percent*100, 1), "\\% $\\downarrow$") ), percent_temp = kableExtra::cell_spec( percent_temp, "latex", background = dplyr::case_when( percent > longunread_avg$Total ~ "#F08080", percent>0.05 & percent < longunread_avg$Total ~ "#FFe699", percent < 0.05 ~ "#C6E0B4", TRUE ~ "#FFFFFF"), escape = FALSE), TotalMeters = scales::comma(TotalMeters, digits = 0), PureLUMs = scales::comma(PureLUMs, digits = 0) ) %>% dplyr::arrange( dplyr::desc( percent ) ) %>% dplyr::select(Wholesaler, TotalMeters, PureLUMs, percent_temp) knitr::kable( top10_long_whole, "latex", col.names = c("Wholesaler", "Total number of meters", "Number of Long unread meters", "Percentage of Long unread meters"), booktabs = TRUE, escape=FALSE, linesep = "", caption = "Wholesaler area Long Unread ranking", align = c( "l", rep( "r", ncol(top10_long_whole)-1) ) ) %>% kableExtra::kable_styling( latex_options = c("hold_position", "striped", "scale_down") ) %>% kableExtra::row_spec( 1:nrow(top10_long_whole), hline_after = TRUE)
\arrayrulecolor{white}
knitr::kable(table_legend_long, "latex", booktabs = TRUE, col.names = c("", " ", " "), linesep = "", escape = FALSE ) %>% kableExtra::kable_styling( latex_options = c("hold_position", "scale_down") )
\arrayrulecolor{black}
Only Wholesaler areas with more than 100 meters are included here.
The arrows indicate the change in percentage of Long Unread meters compared to last month
\newpage
\blandscape
graph_data <- MOSLR::MPOP_data_prep(df.longunread = longunread,tp.details = tp_details, longunread.table = TRUE, by = "Pair", my.dir = my_dir) MOSLR::bubble_chart(df = graph_data, longunread.graph = TRUE, by = "Pair", vertical.sep = longunread_avg$Total)
This chart shows relative volumes of Long Unread meters by Wholesaler-Retailer pairing and their movement over the past 12 months.
\newpage \elandscape
top10_long_pair <- graph_data%>% dplyr::mutate( percent_temp = ifelse( percent - last_percent > 0, paste0(round(percent*100, 1), "\\% $\\uparrow$"), paste0(round(percent*100, 1), "\\% $\\downarrow$") ), percent_temp = kableExtra::cell_spec( percent_temp, "latex", background = dplyr::case_when( percent > longunread_avg$Total ~ "#F08080", percent>0.05 & percent < longunread_avg$Total ~ "#FFE699", percent < 0.05 ~ "#C6E0B4", TRUE ~ "#FFFFFF"), escape = FALSE), TotalMeters = scales::comma(TotalMeters, digits = 0), PureLUMs = scales::comma(PureLUMs, digits = 0) ) %>% dplyr::arrange( dplyr::desc( percent ) ) %>% dplyr::select(Pair, TotalMeters, PureLUMs, percent_temp) knitr::kable( top10_long_pair, "latex", col.names = c("Pairing", "Total number of meters", "Number of Long unread meters", "Percentage of Long unread meters"), booktabs = TRUE, escape=FALSE, linesep = "", caption = "Pairing Long unread ranking", align = c( "l", rep( "r", ncol(top10_long_ret)-1) ) ) %>% kableExtra::kable_styling( latex_options = c("hold_position", "striped", "scale_down") ) %>% kableExtra::row_spec( 1:nrow(top10_long_pair), hline_after = TRUE) %>% kableExtra::column_spec( 1, width = "6.5cm" )
\arrayrulecolor{white}
knitr::kable(table_legend_long, "latex", booktabs = TRUE, col.names = c("", " ", " "), linesep = "", escape = FALSE ) %>% kableExtra::kable_styling( latex_options = c("hold_position", "scale_down") )
\arrayrulecolor{black}
Only Wholesaler-Retailer pairings with more than 3000 meters are included here.
The arrows indicate the change in percentage of Long Unread meters compared to last month
\clearpage \newpage \blandscape
longunreadtotal <- tidyr::pivot_wider( dplyr::arrange( longunread%>% dplyr::filter( Period == max(longunread$Period) ), WholesalerID), id_cols = WholesalerID, names_from = RetailerID, values_from = Meters_Unread_in_12mo ) %>% dplyr::bind_rows( dplyr::summarise_all( ., dplyr::funs(if(is.numeric(.)) sum(., na.rm = TRUE) else "Total") ) ) %>% dplyr::select( WholesalerID, sort(names(.) ) ) %>% dplyr::mutate( Total = rowSums( dplyr::select(., -WholesalerID), na.rm = TRUE) ) %>% dplyr::mutate_if( is.numeric, ~scales::comma(., accuracy = 1) ) %>% dplyr::mutate_all( ~replace( ., is.na(.), "" ) ) knitr::kable( longunreadtotal, "latex", booktabs = TRUE, linesep = "", caption = "Total number of meters unread in 12 months", align = c( "l", rep( "c", ncol(longunreadtotal)-1 ) ), col.names = c( "", colnames(longunreadtotal)[2:ncol(longunreadtotal)]) ) %>% kableExtra::kable_styling( latex_options = c( "hold_position", "scale_down", "striped" ), stripe_color = "blizzardblue" ) %>% kableExtra::column_spec( ncol(longunreadtotal)-1, border_right = TRUE ) %>% kableExtra::row_spec( 0, angle = 90 ) %>% kableExtra::row_spec( nrow(longunreadtotal)-1, hline_after = TRUE ) %>% kableExtra::row_spec( nrow(longunreadtotal), bold = TRUE ) %>% kableExtra::column_spec( ncol(longunreadtotal), bold = TRUE )
longunreadtotal_Since_MO <- tidyr::pivot_wider( dplyr::arrange( longunread%>% dplyr::filter( Period == max(longunread$Period) ), WholesalerID), id_cols = WholesalerID, names_from = RetailerID, values_from = Meters_Unread_Since_MO ) %>% dplyr::bind_rows( dplyr::summarise_all( ., dplyr::funs(if(is.numeric(.)) sum(., na.rm = TRUE) else "Total") ) ) %>% dplyr::select( WholesalerID, sort(names(.) ) ) %>% dplyr::mutate( Total = rowSums( dplyr::select(., -WholesalerID), na.rm = TRUE) ) %>% dplyr::mutate_if( is.numeric, ~scales::comma(., accuracy = 1) ) %>% dplyr::mutate_all( ~replace( ., is.na(.), "" ) ) knitr::kable( longunreadtotal_Since_MO, "latex", booktabs = TRUE, linesep = "", caption = "Total number of meters unread since Market Opening", align = c( "l", rep( "c", ncol(longunreadtotal_Since_MO)-1 ) ), col.names = c( "", colnames(longunreadtotal_Since_MO)[2:ncol(longunreadtotal_Since_MO)]) ) %>% kableExtra::kable_styling( latex_options = c( "hold_position", "scale_down", "striped" ), stripe_color = "blizzardblue" ) %>% kableExtra::column_spec( ncol(longunreadtotal_Since_MO)-1, border_right = TRUE ) %>% kableExtra::row_spec( 0, angle = 90 ) %>% kableExtra::row_spec( nrow(longunreadtotal_Since_MO)-1, hline_after = TRUE ) %>% kableExtra::row_spec( nrow(longunreadtotal_Since_MO), bold = TRUE ) %>% kableExtra::column_spec( ncol(longunreadtotal_Since_MO), bold = TRUE )
percent <- longunread%>% dplyr::filter( Period == max(longunread$Period) ) %>% dplyr::mutate( percent = scales::percent( Meters_Unread_in_12mo/TotalMeters) ) %>% tidyr::pivot_wider( ., id_cols = WholesalerID, names_from = RetailerID, values_from = percent ) total_percent <- longunread%>% dplyr::filter( Period == max(longunread$Period) ) %>% dplyr::summarise( Total = paste(round(100*sum(Meters_Unread_in_12mo)/sum(TotalMeters),1),"%") ) %>% dplyr::mutate( WholesalerID = "Total" ) ret_percent <- longunread%>% dplyr::filter( Period == max(longunread$Period) ) %>% dplyr::group_by(RetailerID) %>% dplyr::summarise( percent = paste(round(100*sum(Meters_Unread_in_12mo)/sum(TotalMeters),1),"%") ) %>% dplyr::mutate( WholesalerID = "Total" ) %>% tidyr::pivot_wider( id_cols = WholesalerID, names_from = RetailerID, values_from = percent ) whole_percent <- longunread%>% dplyr::filter( Period == max(longunread$Period) ) %>% dplyr::group_by( WholesalerID ) %>% dplyr::summarise( Total = paste(round(100*sum(Meters_Unread_in_12mo)/sum(TotalMeters),1),"%") ) unread_percent <- dplyr::bind_rows( dplyr::arrange( percent, WholesalerID), ret_percent ) %>% dplyr::left_join( dplyr::bind_rows( whole_percent, total_percent ), by = "WholesalerID" ) %>% dplyr::mutate_all( ~replace(., is.na(.),"") ) knitr::kable( unread_percent, "latex", booktabs = TRUE, linesep = "", caption = "Percentage of meters unread in 12 months", align = c( "l", rep( "c", ncol(unread_percent)-1) ), col.names = c( "", colnames(unread_percent)[2:ncol(unread_percent)] ) ) %>% kableExtra::kable_styling( latex_options = c("hold_position", "scale_down", "striped"), stripe_color = "blizzardblue" ) %>% kableExtra::column_spec( ncol(unread_percent)-1, border_right = TRUE ) %>% kableExtra::row_spec( 0, angle = 90 ) %>% kableExtra::row_spec( nrow(unread_percent)-1, hline_after = TRUE ) %>% kableExtra::row_spec( nrow(unread_percent), bold = TRUE ) %>% kableExtra::column_spec( ncol(unread_percent), bold = TRUE)
\newpage
\elandscape
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.