Load required packages
# Load required packages
library(tidyverse)
# Source shared helpers (theme, helpers, fact_helpers, collate_fact)
source(here::here("scripts", "R", "_common.R"))Contributing to national economic growth
This chapter tracks indicators related to the West of England’s contribution to national economic growth. Up to 10 indicators can be included, covering metrics like GVA, productivity, business growth, innovation, and employment.
This example demonstrates how to create an indicator using R. It loads data, processes it, creates a chart with WECA branding, and presents findings.
# Load required packages
library(tidyverse)
# Source shared helpers (theme, helpers, fact_helpers, collate_fact)
source(here::here("scripts", "R", "_common.R"))# Load example indicator data
# In your actual analysis, replace this with your real data source
data <- load_csv(here::here("data", "examples", "example_indicator.csv"))
# Preview the data structure
head(data)# A tibble: 6 × 6
area year indicator_name indicator_value target_value national_average
<chr> <dbl> <chr> <dbl> <dbl> <dbl>
1 Bristol 2015 Employment Rate 72.3 75 73.1
2 Bristol 2016 Employment Rate 73.5 75 73.8
3 Bristol 2017 Employment Rate 74.2 75 74.2
4 Bristol 2018 Employment Rate 75.1 75 74.9
5 Bristol 2019 Employment Rate 76.3 75 75.4
6 Bristol 2020 Employment Rate 73.8 75 74.1
# Filter and process the data
# This example calculates the latest value and year-on-year change
processed <- data %>%
filter(indicator_name == "Sample Economic Metric") %>%
arrange(year) %>%
mutate(
# Calculate year-on-year change
yoy_change = indicator_value - lag(indicator_value),
yoy_pct = (yoy_change / lag(indicator_value)) * 100
)
# Get the latest value for summary
latest <- processed %>%
filter(year == max(year)) %>%
pull(indicator_value)
latest_year <- processed %>%
filter(year == max(year)) %>%
pull(year)The most recent value for this indicator is **** (as of ).
# Create a line chart showing the trend over time
ggplot(processed, aes(x = year, y = indicator_value)) +
geom_line(colour = weca_palette["forest_green"], linewidth = 1.2) +
geom_point(colour = weca_palette["forest_green"], size = 3) +
scale_y_continuous(labels = scales::comma) +
labs(
title = "Sample Economic Indicator Trend",
x = "Year",
y = "Indicator Value",
caption = "Source: Example data"
) +
theme_weca()Error in `weca_palette["forest_green"]`:
! object of type 'closure' is not subsettable
Data source: [Specify source] Last updated: [Date] Refresh schedule: [Annual/Quarterly/Monthly]
[Describe what this indicator measures and why it matters for economic growth]
# Your code here
# Follow the pattern from the worked example above:
# 1. Load data
# 2. Process/filter/aggregate
# 3. Create visualization with theme_weca()
# 4. Calculate key statistics[Your narrative findings here]
Data source: Last updated: Refresh schedule:
[Repeat structure above - add up to 10 indicators total]
[Summary of key findings across all indicators in this chapter. What is the overall picture for economic growth?]
The example below shows how to achieve the same analysis using Python instead of R.
# import pandas as pd
# import matplotlib.pyplot as plt
# from pathlib import Path
#
# # Load data with project-relative path
# project_root = Path(__file__).parent.parent.parent # Navigate to project root
# data_path = project_root / "data" / "examples" / "example_indicator.csv"
# df = pd.read_csv(data_path)
#
# # Filter and process
# economic_data = df[df['indicator_name'] == 'Sample Economic Metric'].copy()
# economic_data = economic_data.sort_values('year')
#
# # Calculate year-on-year change
# economic_data['yoy_change'] = economic_data['indicator_value'].diff()
# economic_data['yoy_pct'] = (economic_data['yoy_change'] /
# economic_data['indicator_value'].shift(1)) * 100
#
# # Create chart (matplotlib - theme_weca for Python to be added later)
# fig, ax = plt.subplots(figsize=(10, 6))
# ax.plot(economic_data['year'], economic_data['indicator_value'],
# marker='o', linewidth=2, color='#1D4F2B')
# ax.set_xlabel('Year')
# ax.set_ylabel('Indicator Value')
# ax.set_title('Sample Economic Indicator Trend')
# plt.show()