Skip to content

Commit

Permalink
Merge pull request #182 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
More style cleanups
  • Loading branch information
ldecicco-USGS authored May 2, 2017
2 parents 4a48147 + 197ec39 commit ba15bc6
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: toxEval
Type: Package
Title: ToxCast Evaluations
Version: 0.3.3
Date: 2017-04-28
Version: 0.3.4
Date: 2017-05-02
Authors@R: c( person("Steven", "Corsi", role = c("aut"),
email = "[email protected]"),
person("Laura", "DeCicco", role = c("aut","cre"),
Expand Down
12 changes: 9 additions & 3 deletions R/plot_chemical_boxplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @param chemicalSummary data frame from \code{graph_chem_data}
#' @param manual_remove vector of categories to remove
#' @param mean_logic logical \code{TRUE} is mean, \code{FALSE} is maximum
#' @param plot_ND logical whether or not to plot the non-detects
#' @export
#' @import ggplot2
#' @importFrom stats median quantile
Expand Down Expand Up @@ -32,7 +33,8 @@
#' plot_chemical_boxplots(chemicalSummary)
plot_chemical_boxplots <- function(chemicalSummary,
manual_remove=NULL,
mean_logic = FALSE){
mean_logic = FALSE,
plot_ND = TRUE){

site <- EAR <- sumEAR <- meanEAR <- groupCol <- nonZero <- ".dplyr"
chnm <- Class <- maxEAR <- ".dplyr"
Expand All @@ -41,16 +43,20 @@ plot_chemical_boxplots <- function(chemicalSummary,
"#FFFF00","#78C15A","#79AEAE","#FF0000","#00FF00","#B1611D",
"#FFA500","#F4426e", "#800000", "#808000")

if(!plot_ND){
chemicalSummary <- chemicalSummary[chemicalSummary$EAR > 0,]
}

if(length(unique(chemicalSummary$Class)) > length(cbValues)){
n <- length(unique(chemicalSummary$Class))

if(n > 20 & n<30){
cbValues <- c(brewer.pal(n = 12, name = "Set3"),
brewer.pal(n = 8, name = "Set2"),
brewer.pal(n = n-20, name = "Set1"))
brewer.pal(n = max(c(3,n-20)), name = "Set1"))
} else if (n <= 20){
cbValues <- c(brewer.pal(n = 12, name = "Set3"),
brewer.pal(n = n-12, name = "Set2"))
brewer.pal(n = max(c(3,n-12)), name = "Set2"))
} else {
cbValues <- colorRampPalette(brewer.pal(11,"Spectral"))(n)
}
Expand Down
9 changes: 7 additions & 2 deletions R/plot_group_boxplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param category either "Biological", "Chemical Class", or "Chemical"
#' @param manual_remove vector of categories to remove
#' @param mean_logic logical \code{TRUE} is mean, \code{FALSE} is maximum
#' @param plot_ND logical whether or not to plot the non-detects
#' @export
#' @import ggplot2
#' @importFrom stats median
Expand Down Expand Up @@ -35,19 +36,23 @@
plot_tox_boxplots <- function(chemicalSummary,
category = "Biological",
manual_remove = NULL,
mean_logic = FALSE){
mean_logic = FALSE,
plot_ND = TRUE){

match.arg(category, c("Biological","Chemical Class","Chemical"))

site <- EAR <- sumEAR <- meanEAR <- groupCol <- nonZero <- ".dplyr"

if(category == "Chemical"){

chemPlot <- plot_chemical_boxplots(chemicalSummary, mean_logic = mean_logic)
chemPlot <- plot_chemical_boxplots(chemicalSummary, mean_logic = mean_logic, plot_ND = plot_ND)
return(chemPlot)

} else {

if(!plot_ND){
chemicalSummary <- chemicalSummary[chemicalSummary$EAR > 0,]
}
single_site <- length(unique(chemicalSummary$site)) == 1

bioPlot <- ggplot()+
Expand Down
9 changes: 8 additions & 1 deletion R/plot_heat_chemical.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ plot_heat_chemicals <- function(graphData, chem_site){
#' @param category either "Biological", "Chemical Class", or "Chemical"
#' @param manual_remove vector of categories to remove
#' @param mean_logic logical \code{TRUE} is mean, \code{FALSE} is maximum
#' @param plot_ND logical whether or not to plot the non-detects
#' @export
#' @import ggplot2
#' @importFrom stats median
Expand Down Expand Up @@ -157,12 +158,18 @@ plot_tox_heatmap <- function(chemicalSummary,
chem_site,
category = "Biological",
manual_remove = NULL,
mean_logic = FALSE){
mean_logic = FALSE,
plot_ND = TRUE){

match.arg(category, c("Biological","Chemical Class","Chemical"))

SiteID <- site_grouping <- `Short Name` <- chnm <- maxEAR <- ".dplyr"
site <- EAR <- sumEAR <- meanEAR <- ".dplyr"

if(!plot_ND){
chemicalSummary <- chemicalSummary[chemicalSummary$EAR > 0,]
}

if(category == "Chemical"){
graphData <- graph_chem_data(chemicalSummary, mean_logic=mean_logic)
plot_back <- plot_heat_chemicals(graphData=graphData, chem_site=chem_site)
Expand Down
5 changes: 4 additions & 1 deletion inst/shiny/boxPlot.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
output$graphGroup <- renderPlot({

catType = as.numeric(input$radioMaxGroup)

plot_ND = input$plot_ND

chemicalSummary <- chemicalSummary()

Expand All @@ -12,7 +14,8 @@ output$graphGroup <- renderPlot({

bioPlot <- plot_tox_boxplots(chemicalSummary,
category = category,
mean_logic = as.logical(input$meanEAR))
mean_logic = as.logical(input$meanEAR),
plot_ND = plot_ND)

if(catType == 2){
ggsave("boxPlot.png",
Expand Down
13 changes: 6 additions & 7 deletions inst/shiny/heatMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ output$graphHeat <- renderPlot({
validate(
need(!is.null(input$data), "Please select a data set")
)

plot_ND = input$plot_ND_heat
catType = as.numeric(input$radioMaxGroup)

chemicalSummary <- chemicalSummary()
Expand All @@ -22,7 +22,8 @@ output$graphHeat <- renderPlot({

heatMap <- plot_tox_heatmap(chemicalSummary,
chem_site,
category = c("Biological","Chemical","Chemical Class")[catType])
category = c("Biological","Chemical","Chemical Class")[catType],
plot_ND = plot_ND)

ggsave("heatPlot.png",heatMap,bg = "transparent")

Expand All @@ -31,11 +32,9 @@ output$graphHeat <- renderPlot({
})

output$graphHeat.ui <- renderUI({
# heightOfGraph <- 500
# if(as.numeric(input$radioMaxGroup) == 2){
# heightOfGraph <- 800
# }
plotOutput("graphHeat", width = "100%")
height <- PlotHeight()

plotOutput("graphHeat", height = height, width = 800)
})

output$downloadHeatPlot <- downloadHandler(
Expand Down
3 changes: 2 additions & 1 deletion inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ body <- dashboardBody(
),
tabPanel(title = tagList("Box Plots", shiny::icon("bar-chart")),
value="summary",
checkboxInput("plot_ND", "Plot ND's?", TRUE),
uiOutput("graphGroup.ui"),
# div(style = 'overflow-y: scroll', uiOutput("graphGroup.ui")),
downloadButton('downloadBoxPlot', 'Download PNG')
),
tabPanel(title = tagList("Bar Charts", shiny::icon("bar-chart")),
Expand Down Expand Up @@ -176,6 +176,7 @@ body <- dashboardBody(
),
tabPanel(title = tagList("Heat Map", shiny::icon("bar-chart")),
value="heat",
checkboxInput("plot_ND_heat", "Plot ND's?", TRUE),
uiOutput("graphHeat.ui"),
downloadButton('downloadHeatPlot', 'Download PNG')
)
Expand Down
4 changes: 3 additions & 1 deletion man/plot_chemical_boxplots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot_tox_boxplots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot_tox_heatmap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba15bc6

Please sign in to comment.