Created
April 27, 2017 16:31
-
-
Save jamiebono/0e5bbf08f9adf13280bea022500b49f0 to your computer and use it in GitHub Desktop.
A simple script to import a quality measurement data set, transform it, and plot qi charts by organization and measure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Load Prerequisites ==== | |
| library(tidyverse) | |
| library(lubridate) | |
| library(qicharts) | |
| # Read data frame from csv ---- | |
| df <- read.csv("walestest.csv", stringsAsFactors = FALSE) | |
| # Test it once==== | |
| # Create one of Organisation dataframes ---- | |
| df.Abertawe <- df %>% | |
| mutate(Month = ymd(Month)) %>% | |
| filter(Organisation == "Abertawe Bro Morgannwg University Local Health Board Total") %>% | |
| select(Month, Attendances, lessthan4h) # Replace lessthan4h with measure variable | |
| # Plot the test data ---- | |
| qic(y = df.Abertawe$Attendances, chart = 'i', freeze = 24) | |
| # Alternately: ==== | |
| # Create a list of dataframes based on the test dataframe df.Abertawe ---- | |
| df.list <- df %>% | |
| mutate(Month = ymd(Month)) %>% | |
| split(f = .$Organisation) | |
| # Iterate across the list to create named plot objects ---- | |
| plot.list <- lapply(df.list, function(k) qic(y = k$Attendances, chart = 'i', freeze = 24)) #change y variable to select measure | |
| # Call the plot by name ---- | |
| plot(plot.list$`All Wales - All hospital emergency care facilities`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment