Skip to content

Commit

Permalink
#167 stable JPEG save functions
Browse files Browse the repository at this point in the history
also added dynamic sizing of the graphs
  • Loading branch information
andkov committed Feb 20, 2017
1 parent 33ce9dc commit 4c91c9b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 30 deletions.
101 changes: 78 additions & 23 deletions reports/correlation-3/correlation-3-pc.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,36 @@ catalog <- catalog %>%
dplyr::mutate(
process_b = ifelse(study_name == "map" & process_b == "matrices", "raven_standard", process_b),
process_b = ifelse(study_name == "lasa" & process_b == "raven", "raven_color_ab", process_b)
) #%>%
# dplyr::filter(
# ! process_b == "trailsb"
# )
) %>%
dplyr::filter(
! process_b == "trailsb"
)

# d <- catalog %>%
# dplyr::filter(process_b == "trailsb")

# ---- save-data-for-tables --------------------------
for(track in c("gait","grip","pulmonary")){
for(gender in c("male","female")){
for(format in c("full","brief"))
catalog %>%
dplyr::filter(model_type == "aehplus",model_number=="b1") %>%
prettify_catalog() %>%
save_corr_table(
track,
gender,
format,
"./reports/correlation-3/table-data/")
}
}
# for(track in c("gait","grip","pulmonary")){
# for(gender in c("male","female")){
# for(format in c("full","brief"))
# catalog %>%
# dplyr::filter(model_type == "aehplus",model_number=="b1") %>%
# prettify_catalog() %>%
# save_corr_table(
# track,
# gender,
# format,
# "./reports/correlation-3/table-data/")
# }
# }

# ---- dummy -------------
# track values is defined in Rmd
# track = "pulmonary"
# gender = "male"

# ---- table-dynamic -----------------------------------------------------------
# ---- table-dynamic, eval=FALSE, echo=F -----------------------------------------------------------
# track = "pulmonary"

d <- catalog %>%
dplyr::filter(
Expand Down Expand Up @@ -124,9 +125,60 @@ d %>%
options = list(pageLength = 6, autoWidth = TRUE)
)




# ----- custom-save-forest --------------------------------
track = "pulmonary"
data_forest <- get_forest_data(catalog,track = track) %>%
rename_domains(track) %>%
dplyr::filter(
model_number == "b1"
,model_type == "aehplus"
) %>%
dplyr::mutate(
domain = gsub("delayed/working","working", domain)
)

# print single
# data_forest %>% print_forest_plot("verbal knowledge","male")
# data_forest %>% print_forest_plot("memory","male")
# print all

domain_cycle <- setdiff(unique(data_forest$domain),NA)
subgroup_cycle <- unique(data_forest$subgroup)

for(dom in domain_cycle){
# cat("\n##",dom,"\n")
for(gender in subgroup_cycle){
dom = domain_cycle[3]
gender = subgroup_cycle[1]
# n_lines = 13
n_lines <- data_forest %>%
dplyr::filter(domain==dom,subgroup==gender) %>%
nrow()
# save graphic
path_save = paste0("./reports/correlation-3/forest-plot-pulmonary/jpeg/",
track,"-",dom,"-",gender,".jpg")
jpeg(
filename = path_save,
width = 900,
height = 140 + 20*n_lines,
units = "px",
pointsize = 12,
quality = 100
)
data_forest %>% print_forest_plot(dom,gender)
dev.off()
}
}




# ---- print-forest -----------------

# track = "pulmonary"
track = "pulmonary"
data_forest <- get_forest_data(catalog,track = track) %>%
rename_domains(track) %>%
dplyr::filter(
Expand All @@ -150,6 +202,9 @@ for(dom in domain_cycle){
}
}

# ----- custom-save-forest --------------------------------


# ---- table-static-full ------------------------------------------------------------
cat("\n#Group by domain\n")
for(gender in c("male","female")){
Expand Down Expand Up @@ -266,8 +321,8 @@ path_grip_focus <- "./reports/correlation-3/correlation-3-grip-focus.Rmd"

# allReports <- path_pulmonary_full
# allReports <- path_pulmonary_short
allReports <- c(path_pulmonary_full,path_pulmonary_focus)
# allReports <- c(path_pulmonary_summary)
# allReports <- c(path_pulmonary_full,path_pulmonary_focus)
allReports <- c(path_pulmonary_summary)
# allReports <- path_gait_full
# allReports <- path_gait_short
# allReports <- path_grip_full
Expand All @@ -282,10 +337,10 @@ for( pathFile in pathFilesToBuild ) {

rmarkdown::render(input = pathFile,
output_format=c(
# "html_document" # set print_format <- "html" in seed-study.R
"html_document" # set print_format <- "html" in seed-study.R
# "pdf_document"
# ,"md_document"
"word_document" # set print_format <- "pandoc" in seed-study.R
# "word_document" # set print_format <- "pandoc" in seed-study.R
),
clean=TRUE)
}
Expand Down
19 changes: 12 additions & 7 deletions reports/correlation-3/support-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ print_forest_plot <- function(
numformat(forest_summary["mean"]),
numformat(forest_summary["lower"]),
numformat(forest_summary["upper"]))


d_value <- data.frame(
"mean" = c(NA,NA,d$mean, NA, forest_summary["mean"]),
"lower"= c(NA,NA,d$lower,NA, forest_summary["lower"]),
Expand All @@ -455,16 +453,23 @@ print_forest_plot <- function(
# upper = d$upper,
align = c("r","r","l","c","c","c"),
new_page = TRUE,
# is.summary = c(FALSE,FALSE,rep(FALSE,n_rows-1),TRUE),
is.summary = c(TRUE,TRUE,rep(FALSE,n_rows-1),TRUE),
clip = c(-1,1),
clip = c(-1,1),
# xlog = TRUE,
txt_gp = fpTxtGp(label = list(gpar(fontfamily = "",cex=1),
gpar(fontfamily = "",cex=1),
gpar(fontfamily = "",cex=1),
gpar(fontfamily = "",cex=1)
),
ticks = gpar(fontfamily = "", cex=1),
xlab = gpar(fontfamily = "HersheySerif", cex = 1.5)
),
col = fpColors(box = "black",
line = "black",
summary = "black"),
# col = fpColors(box = "royalblue",
# line = "darkblue",
# summary = "royalblue"),
hrzl_lines = gpar(col="#444444"),
# hrzl_lines = list("3" = gpar(lty=1)),
hrzl_lines = gpar(col="#444444"),
graph.pos = 5,
title = paste0("Slope correlations in ",toupper(domain_)," domain among ",toupper(subgroup_),"S")
# title = paste0("Slope correlations among ",toupper(subgroup_),"S")
Expand Down

0 comments on commit 4c91c9b

Please sign in to comment.