[R] ggplot2 different Y axis scales

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Nov 7 00:28:10 CET 2015


Read the help for facet_grid, in particular about the scale parameter. I don't think you can individually control it though. 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On November 6, 2015 2:04:54 PM PST, David Doyle <kydaviddoyle at gmail.com> wrote:
>Hello Everyone,
>
>I'm using the following code to plot sulfate concentrations vs. time
>for
>several groundwater wells at one time.  Normally I need the scales to
>all
>be the same but in the case of sulfate I need to use a different scale
>for
>each well.  This is because some of my wells have very high / wide
>ranges
>(MW04 ranges from 4 - 3,000) where some have very small ranges (MW06
>ranges
>from 13 - 34).
>
>Is there a way that I can  have qqplot2 automatically scale each well
>or a
>way I could enter a scale range.?  For example I would like MW04 to
>have a
>Y axis scale from 0 - 3,000 and MW06 to have a Y axis scale from 0 - 40
>
>I am using
>RStudio version 0.99.484
>R i386 3.2.2
>ggplott2 ver 1.0.1
>in a Windows 7 environment.
>
>Thank you for your time
>David Doyle
>
>
>library(ggplot2)
>SS <-read.csv("http://doylesdartden.com/Stats/SS.csv", sep=",")
>
>#Sets whic are detections and nondetects
>SS$Detections <- ifelse(SS$D_Sulfate==1, "Detected", "NonDetect")
>png(file="Sulfate.png",width=2400,height=3000,res=300)
>#does the plot
>p <- ggplot(data = SS, aes(x=Year, y=Sulfate, col=Detections)) +
>  geom_point(aes(shape=Detections))  +
>
>  ##sets the colors
>  scale_colour_manual(values=c("black","red")) +
>
>  #location of the legend
>  theme(legend.position=c("none")) +
>
>  #sets the line color, type and size
>  geom_line(colour="black", linetype="dotted", size=0.5) +
>  ylab("Sulfate (mg/L)") +
>  ##Graph title
>  ggtitle("Figure 6-30
>          Sandstone Sulfate Time Series")
>
>## does the graph using the Well IDs as the different wells.
>p + facet_grid(Well ~ .)
>dev.off()
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list