Thanks for the tip. Its kind of difficult to do this in reprex, since there is a Rmarkdown file (which I could not reprex the full contents) and then the Rmarkdown Rendering Script that is used to render the different reports by center. But I have tried my best. Any suggestions on how to improve this post are welcome! Also, side note, I know some of my code isn't the most succinct, I'm more of an analytic programmer in R.
Load data
data.frame(stringsAsFactors=FALSE,
CenterID = c(4763L, 4762L, 5441L, 4722L, 4726L),
GrantID = c("Grantee ID 4544", "Grantee ID 4544",
"Grantee ID 5141", "Grantee ID 4540",
"Grantee ID 4540"),
MonitorID = c(10L, 10L, 10L, 3L, 3L),
Qi1_SA = c(3L, 5L, 5L, 4L, 3L),
Qi1 = c(4, 5, 5, 4, 5),
Qi2_SA = c(3L, 5L, 3L, 4L, 4L),
Qi2 = c(5, 5, 5, 5, 5),
Qi3_SA = c(3L, 4L, 5L, 4L, 3L),
Qi3 = c(5, 5, 5, 4, 1),
Qi4_SA = c(3, 5, 2, 3, 3),
Qi4 = c(0, 4, 1, 3, 3),
Qi5_SA = c(3, 5, 3, 3, 3),
Qi5 = c(0, 5, 3, 5, 5),
Qi6_SA = c(5L, 5L, 5L, 4L, 3L),
Qi6 = c(5, 5, 5, 5, 3),
Qi7_SA = c(5L, 5L, 5L, 5L, 5L),
Qi7 = c(5, 5, 5, 5, 5),
Qi11_SA = c(3, 5, 4, 5, 4),
Qi11 = c(2, 5, 3, 5, 4),
Qi12_SA = c(3L, 5L, 5L, 5L, 4L),
Qi12 = c(5, 5, 5, 5, 5),
Qi13_SA = c(3L, 5L, 3L, 5L, 4L),
Qi13 = c(0, 5, 2, 5, 4),
Qi14_SA = c(3L, 5L, 4L, 4L, 4L),
Qi14 = c(5L, 5L, 4L, 5L, 4L),
Qi17_SA = c(3, 4, 5, 5, 3),
Qi17 = c(4, 5, 5, 5, 3))
#> CenterID GrantID MonitorID Qi1_SA Qi1 Qi2_SA Qi2 Qi3_SA Qi3 Qi4_SA
#> 1 4763 Grantee ID 4544 10 3 4 3 5 3 5 3
#> 2 4762 Grantee ID 4544 10 5 5 5 5 4 5 5
#> 3 5441 Grantee ID 5141 10 5 5 3 5 5 5 2
#> 4 4722 Grantee ID 4540 3 4 4 4 5 4 4 3
#> 5 4726 Grantee ID 4540 3 3 5 4 5 3 1 3
#> Qi4 Qi5_SA Qi5 Qi6_SA Qi6 Qi7_SA Qi7 Qi11_SA Qi11 Qi12_SA Qi12 Qi13_SA Qi13
#> 1 0 3 0 5 5 5 5 3 2 3 5 3 0
#> 2 4 5 5 5 5 5 5 5 5 5 5 5 5
#> 3 1 3 3 5 5 5 5 4 3 5 5 3 2
#> 4 3 3 5 4 5 5 5 5 5 5 5 5 5
#> 5 3 3 5 3 3 5 5 4 4 4 5 4 4
#> Qi14_SA Qi14 Qi17_SA Qi17
#> 1 3 5 3 4
#> 2 5 5 4 5
#> 3 4 4 5 5
#> 4 4 5 5 5
#> 5 4 4 3 3
Created on 2019-12-12 by the reprex package (v0.3.0)
Rmarkdown report, which was unable to be put into with the reprex package, so I just pasted it here.
title: "Program Monitoring"
author: "Center-Level Report"
date: "Fall 2019"
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage[dvipsnames]{xcolor}
- \definecolor{othergreen}{RGB}{32, 176, 75}
output:
pdf_document
knitr::opts_chunk$set(echo = TRUE)
options(kableExtra.latex.load_packages = FALSE)
#source("ACE_clean_data.R")
load("fall_ace_center.Rdata")
library(ggplot2)
library(tidyverse)
library(tidyr)
library(dplyr)
library(readr)
library(reshape2)
library(kableExtra)
library(knitr)
library(condformat)
fall_ace_sub <-
fall_ace_center %>%
dplyr::filter(CenterID == CID) #Replace wth CenterID placeholder for Center Level Report
# Objects for points of reference.
#CenterID <- fall_ace_sub$CenterID
MS <- c("Qi1", "Qi2", "Qi3", "Qi4", "Qi5", "Qi6", "Qi7", "Qi11", "Qi12", "Qi13", "Qi14", "Qi17")
SA <- c("Qi1_SA", "Qi2_SA", "Qi3_SA", "Qi4_SA", "Qi5_SA", "Qi6_SA", "Qi7_SA", "Qi11_SA", "Qi12_SA", "Qi13_SA", "Qi14_SA", "Qi17_SA")
CC_cat1 <- c("Qi1", "Qi2", "Qi3", "Qi4", "Qi5", "Qi6", "Qi7", "Qi1_SA", "Qi2_SA", "Qi3_SA", "Qi4_SA", "Qi5_SA", "Qi6_SA", "Qi7_SA")
#Create subset of dataset to develop tables for figures and tables.
fall_ace_ctrF <-
fall_ace_sub %>%
dplyr::select(Qi1:Qi17, Qi1_SA:Qi17_SA)%>%
t()
fall_ace_ctr1 <- data.frame(rownames_to_column(as.data.frame(fall_ace_ctrF, var = "Qi")))
fall_ace_ctr_fig <-
fall_ace_ctr1 %>%
mutate(score_type = ifelse(rowname %in% MS, "Monitor Score", "Self-Assessment Score"),
CCcat = ifelse(rowname %in% CC_cat1, "cat1", "cat2"),
rowname = recode(rowname,
"Qi1_SA" = "Qi1",
"Qi2_SA" = "Qi2",
"Qi3_SA" = "Qi3",
"Qi4_SA" = "Qi4",
"Qi5_SA" = "Qi5",
"Qi6_SA" = "Qi6",
"Qi7_SA" = "Qi7",
"Qi11_SA" = "Qi11",
"Qi12_SA" = "Qi12",
"Qi13_SA" = "Qi13",
"Qi14_SA" = "Qi14",
"Qi17_SA" = "Qi17"))
names(fall_ace_ctr_fig) <- c("Qi", "score", "score_type", "CCcat")
fall_ace_ctr_fig1 <-
fall_ace_ctr_fig %>%
mutate(Qi =factor(Qi, c("Qi1", "Qi2", "Qi3", "Qi4", "Qi5", "Qi6", "Qi7", "Qi11", "Qi12", "Qi13", "Qi14", "Qi17")),
score_type = factor(score_type, levels = c("Self-Assessment Score", "Monitor Score")))
fall_ace_sub1a <-
fall_ace_sub %>%
dplyr::select("Qi1", "Qi2", "Qi3", "Qi4", "Qi5", "Qi6", "Qi7", "Qi11", "Qi12", "Qi13", "Qi14", "Qi17")%>%
t()
fall_ace_sub1 <- data.frame(rownames_to_column(as.data.frame(fall_ace_sub1a, var = "Qi")))
names(fall_ace_sub1) <- c("Qi", "Monitor Score")
fall_ace_sub2a <-
fall_ace_sub %>%
dplyr::select("Qi1_SA", "Qi2_SA", "Qi3_SA", "Qi4_SA", "Qi5_SA", "Qi6_SA", "Qi7_SA", "Qi11_SA", "Qi12_SA", "Qi13_SA", "Qi14_SA", "Qi17_SA")
names(fall_ace_sub2a) <- c("Qi1", "Qi2", "Qi3", "Qi4", "Qi5", "Qi6", "Qi7", "Qi11", "Qi12", "Qi13", "Qi14", "Qi17")
fall_ace_sub2 <- data.frame(rownames_to_column(as.data.frame(t(fall_ace_sub2a), var = "Qi")))
names(fall_ace_sub2) <- c("Qi", "Self-Assessment Score")
fall_ace_ctr_tbl <- dplyr::right_join(fall_ace_sub2, fall_ace_sub1, by = "Qi")
cc_table_fall_full <- read.csv("CC_QI_Text_table.csv")
cc_table_fall <- select(cc_table_fall_full, -Qi)
names(cc_table_fall) <- gsub("\\.", " ", names(cc_table_fall))
cc_table_fall_short <- read.csv("CC_QI_Text_table_short.csv")
cc_table_fall_cc <- select(cc_table_fall_short, -Qi)
names(cc_table_fall_cc) <- gsub("\\.", " ", names(cc_table_fall_cc))
cc_table_spring <- read.csv("Spring_ACE_CC_Table.csv")
names(cc_table_spring) <- gsub("\\.", " ", names(cc_table_spring))
fall_ace_ctr_tbl1 <- right_join(cc_table_fall_short, fall_ace_ctr_tbl, by = "Qi")
fall_ace_ctr_tbl1 <- select (fall_ace_ctr_tbl1, -Qi)
TEXT
cc_table_fall%>%
kable(align = c("l", "l"), format = "latex") %>%
kable_styling("bordered") %>%
row_spec(0, background = "othergreen", bold = TRUE, align = "c")%>%
column_spec(1, border_left = TRUE)%>%
column_spec(2, border_right = TRUE)%>%
collapse_rows(columns = 1, valign = "top")
This GGPlot causes the dir.name error - if removed, then the HTML color error occurs
fall_ace_ctr_fig1%>%
ggplot(aes(x = Qi, y = score, group = score_type, color = score_type))+
geom_point()+
geom_line()+
geom_hline(yintercept = 3, linetype = "dashed", color = "black") +
theme(legend.position = "bottom", strip.text = element_text(color = "black")) +
labs(linetype = "", color = "", shape = "", x = "Quality Indiators", y = "Scores", title = "Center Qi Indicators Scores - Fall 2019")+
ylim(0,5)
fall_ace_ctr_tbl1%>%
rename(`Compliance Component` = Compliance.Component,
`Quality Indicator`= Quality.Indicators) %>%
kable(align = c("c", "l", "c", "c"), format = "latex") %>%
kable_styling("bordered") %>%
row_spec(0, background = "othergreen", bold = TRUE)%>%
column_spec(1, width = "6em", border_left = TRUE)%>%
column_spec(3, width = "5em")%>%
column_spec(4, border_right = TRUE, width = "5em")%>%
collapse_rows(columns = 1, valign = "top")
#Spring 2019
cc_table_spring%>%
kable(align = c("l", "l", "l"), format = "latex") %>%
kable_styling("bordered") %>%
row_spec(0, background = "othergreen", bold = TRUE, align = "c")%>%
column_spec(1, width = "12em", border_left = TRUE)%>%
column_spec(2, width = "12em")%>%
column_spec(3, width = "12em", border_right = TRUE)%>%
collapse_rows(columns = 1, valign = "top")
FINALLY - The report driver (Rmarkdown Rendering)
# Load packages
library(ggplot2)
library(tidyverse)
library(tidyr)
library(dplyr)
library(readr)
library(reshape2)
#>
#> Attaching package: 'reshape2'
#> The following object is masked from 'package:tidyr':
#>
#> smiths
library(kableExtra)
#>
#> Attaching package: 'kableExtra'
#> The following object is masked from 'package:dplyr':
#>
#> group_rows
rm(list = ls())
#source(file = "ACE_clean_data.R")
load("fall_ace_center.Rdata")
#> Warning in readChar(con, 5L, useBytes = TRUE): cannot open compressed file
#> 'fall_ace_center.Rdata', probable reason 'No such file or directory'
#> Error in readChar(con, 5L, useBytes = TRUE): cannot open the connection
# For Center Reports #
for (CID in unique(fall_ace_center$CenterID)){
rmarkdown::render(input = paste(getwd(), "/Center_Report.Rmd", sep = ""),
output_format = "pdf_document",
output_file = paste(fall_ace_center$CenterID, "-", fall_ace_center$CenterName, " - Fall-2019.pdf", sep=""),
output_dir = paste(getwd(),"/Reports/", fall_ace_center$GranteeID, sep = ""))
}
#> Error in unique(fall_ace_center$CenterID): object 'fall_ace_center' not found
Created on 2019-12-12 by the reprex package (v0.3.0)