From bb50a923f1cf1ba88b04ec7947c04081c32e9e66 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Thu, 26 Jul 2018 11:33:55 -0500 Subject: [PATCH 1/2] Finally figured out why and where the heat legend was getting converted to discrete --- R/plot_group_boxplots.R | 4 ++-- R/plot_heat_chemical.R | 38 +++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/R/plot_group_boxplots.R b/R/plot_group_boxplots.R index 11b859bb..9672a021 100644 --- a/R/plot_group_boxplots.R +++ b/R/plot_group_boxplots.R @@ -362,8 +362,8 @@ prettyLogs <- function(x){ fancyNumbers2 <- function(n){ textReturn <- signif(n,digits = 2) textReturn <- as.character(textReturn) - textReturn[length(textReturn)] <- paste(">",textReturn[length(textReturn)]) - textReturn[1] <- paste("<",textReturn[1]) + # textReturn[length(textReturn)] <- paste(">",textReturn[length(textReturn)]) + # textReturn[1] <- paste("<",textReturn[1]) return(textReturn) } diff --git a/R/plot_heat_chemical.R b/R/plot_heat_chemical.R index 7386faac..8a98538d 100644 --- a/R/plot_heat_chemical.R +++ b/R/plot_heat_chemical.R @@ -84,7 +84,7 @@ plot_tox_heatmap <- function(chemical_summary, chem_site, category = "Biological", - breaks = c(0.00001,0.0001,0.001,0.01,0.1,1,5), + breaks = c(0.00001,0.0001,0.001,0.01,0.1,1,10), manual_remove = NULL, mean_logic = FALSE, sum_logic = TRUE, @@ -111,7 +111,8 @@ plot_tox_heatmap <- function(chemical_summary, plot_back <- plot_heat_chemicals(chemical_summary=chemical_summary, mean_logic=mean_logic, sum_logic=sum_logic, - chem_site=chem_site) + chem_site=chem_site, + breaks=breaks) } else { @@ -125,6 +126,10 @@ plot_tox_heatmap <- function(chemical_summary, left_join(chem_site[, c("SiteID", "site_grouping", "Short Name")], by=c("site"="SiteID")) + single_site <- length(unique(chemical_summary$site)) == 1 + + y_label <- fancyLabels(category, mean_logic, sum_logic, single_site, sep = TRUE) + fill_label <- ifelse(mean_logic, "Mean EAR", "Max EAR") plot_back <- ggplot(data = graphData) + geom_tile(aes(x = `Short Name`, y=category, fill=meanEAR)) + @@ -132,9 +137,9 @@ plot_tox_heatmap <- function(chemical_summary, theme(axis.text.x = element_text( angle = 90,vjust=0.5,hjust = 0.975)) + ylab("") + xlab("") + - labs(fill=fill_label) + - scale_fill_gradient( guide = "legend", - trans = 'log', + labs(fill = fill_label) + + # labs(fill=y_label[["y_label"]], caption = y_label[["caption"]]) + + scale_fill_gradient( trans = 'log', low = "white", high = "steelblue", breaks=breaks, na.value = 'transparent',labels=fancyNumbers2) + @@ -172,7 +177,8 @@ plot_tox_heatmap <- function(chemical_summary, plot_heat_chemicals <- function(chemical_summary, chem_site, mean_logic, - sum_logic){ + sum_logic, + breaks){ SiteID <- site_grouping <- `Short Name` <- chnm <- maxEAR <- ".dplyr" site <- EAR <- sumEAR <- meanEAR <- ".dplyr" @@ -184,25 +190,27 @@ plot_heat_chemicals <- function(chemical_summary, if(!("site_grouping" %in% names(chem_site))){ chem_site$site_grouping <- "Sites" } + single_site <- length(unique(chemical_summary$site)) == 1 + + y_label <- fancyLabels("Chemical", mean_logic, sum_logic, single_site, sep = TRUE) + fill_text <- ifelse(mean_logic, "Mean EAR", "Max EAR") graphData <- graphData %>% left_join(chem_site[, c("SiteID", "site_grouping", "Short Name")], by=c("site"="SiteID")) - fill_text <- ifelse(mean_logic, "Mean EAR", "Max EAR") - heat <- ggplot(data = graphData) + geom_tile(aes(x = `Short Name`, y=chnm, fill=meanEAR)) + theme_bw() + theme(axis.text.x = element_text( angle = 90,vjust=0.5,hjust = 1)) + ylab("") + xlab("") + - labs(fill=fill_text) + - scale_fill_gradient( guide = "legend", - trans = 'log', - low = "white", high = "steelblue", - breaks=c(0.00001,0.0001,0.001,0.01,0.1,1,5), - na.value = 'transparent',labels=fancyNumbers2) + + labs(fill = fill_text) + + # labs(fill=y_label[["y_label"]], caption = y_label[["caption"]]) + + scale_fill_gradient( na.value = 'transparent', + trans = 'log', low = "white", high = "steelblue", + breaks=breaks, + labels=fancyNumbers2) + facet_grid(Class ~ site_grouping, scales="free", space="free") + theme(strip.text.y = element_text(angle=0, hjust=0), strip.background = element_rect(fill="transparent", colour = NA), @@ -210,7 +218,7 @@ plot_heat_chemicals <- function(chemical_summary, panel.spacing = unit(0.05, "lines"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), - plot.background = element_rect(fill = "transparent",colour = NA)) + plot.background = element_rect(fill = "transparent",colour = NA)) return(heat) From 7c524a993c2737978ed2426abd29d8a1712284cc Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Thu, 26 Jul 2018 11:36:21 -0500 Subject: [PATCH 2/2] updating help file too! --- man/plot_tox_heatmap.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/plot_tox_heatmap.Rd b/man/plot_tox_heatmap.Rd index 8c62eb92..8c8cd812 100644 --- a/man/plot_tox_heatmap.Rd +++ b/man/plot_tox_heatmap.Rd @@ -5,7 +5,7 @@ \title{plot_tox_heatmap} \usage{ plot_tox_heatmap(chemical_summary, chem_site, category = "Biological", - breaks = c(1e-05, 1e-04, 0.001, 0.01, 0.1, 1, 5), manual_remove = NULL, + breaks = c(1e-05, 1e-04, 0.001, 0.01, 0.1, 1, 10), manual_remove = NULL, mean_logic = FALSE, sum_logic = TRUE, plot_ND = TRUE, font_size = NA, title = NA) }