USGS-R / smwrGraphs

Moved to: https://code.usgs.gov/water/analysis-tools/smwrGraphs
https://code.usgs.gov/water/analysis-tools/smwrGraphs
Other
18 stars 16 forks source link

stacked QW box plots #37

Closed ldecicco-USGS closed 4 years ago

ldecicco-USGS commented 7 years ago

From an email:

I am trying to create some stacked box plots in R for a QW update. The previous report figure is attached as a reference to what I am trying to recreate (Model figure). I tried to use ggplot to make them, but the USGS formatting is not met and must be edited in an outside program (NH4_concentration). I then tried to use the new smwrGraphs package, but cannot seem to get close to my end product. Any and all suggestions are welcome.

Previous figure: image

Current attempt:

#Concentration Figure#

#ggplot#
library(showtext)
library(ggplot2)
font.add("Univers57","Univers-Condensed.otf")
bpData <- read.csv("Concentration.csv",header=T,colClasses = c("factor","character","numeric"))
showtext.auto()
p1 <- ggplot(data=bpData,aes(x=MAINSTEMSITE,y=DISSOLVEDAMMONIAINMILLIGRAMSPERLITER,color=Period)) + 
        geom_boxplot() +        
      scale_y_log10() +
        annotation_logticks(sides="rl") + 
        theme_bw() + theme(panel.grid = element_blank(),
                           axis.text.x=element_text(angle=90, family="Univers57"),
                           line=element_line(size=0.25))
        p1
ggsave(plot=p1,file="NH4_CONCENTRATION.pdf",width=8,height=8)

#smwrGraphs#
library(smwrGraphs)
font.add("Univers57","Univers-Condensed.otf")
bpData <- read.csv("Concentration.csv",header=T,colClasses = c("factor","character","numeric"))
showtext.auto()
setSweave("Nutrients_conc",8,8)
LO <- setLayout(num.cols=2, num.rows=2, num.graphs=3, explanation=list(grid=4))
GR <- setGraph(1, LO)
bp1 <-boxPlot(bpData, Box=list(type="extended", show.counts=FALSE))
GR <- setGraph(2, LO)
bp1 <-boxPlot(Y,Z, Box=list(type="extended", show.counts=FALSE)
GR <- setGraph(3, LO)
bp1 <-boxPlot(Y,Z, Box=list(type="extended", show.counts=FALSE)
GR <- setGraph("explanation", LO)
addExplanation(bp1, title="Explanation")
graphics.off()

#Loads Figure#

library(showtext)
library(ggplot2)
font.add("Univers57","Univers-Condensed.otf")
bpData <- read.csv("Load.csv",header=T,colClasses = c("factor","character","numeric"))
showtext.auto()
p2 <- ggplot(data=bpData,aes(x=SiteID,y=Load_TonsPerDay,color=Period)) + 
        geom_boxplot() +
        scale_y_log10() +
        annotation_logticks(sides="rl") + 
        theme_bw() + theme(panel.grid = element_blank(),
                           text=element_text(family="Univers57"),
                           line=element_line(size=0.25))
        p2
ggsave(plot=p2,file="test.pdf",width=8,height=8)