[R] Constructing a graph with ggplot2.

Brian Diggs diggsb at ohsu.edu
Thu Sep 26 23:37:39 CEST 2013


On 9/26/2013 1:45 PM, Caitlin wrote:
> Hi all.
>
> I am attempting to graph data from three lab teams with milligrams of
> maltose shown on the y-axis and 5 pH values (5 to 9) on the x-axis as
> labels. Unfortunately, I can't seem to construct the graph in this manner
> using the following code:
>
> ph1 = c(5, 6, 7, 8, 9)
>   ph2 = ph3 = ph1
>
> e1 = c(0.191, 0.154, 0.179, 0.073, 0.009)
> e2 = c(0, 0.029, 0.054, 0.055, 0.024)
> e3 = c(0.019, 0.027, 0.063, 0.029, 0.039)
> set.seed(1)
> df1 <- data.frame(e1 = sort(runif(5, 0.05, 0.25)),
>                     e2 = sort(runif(5, 0.05, 0.25)),
>                     e3 = sort(runif(5, 0.05, 0.25)),
>                     ph1 = sort(runif(5, 1, 100)),
>                     ph2 = sort(runif(5, 1, 100)),
>                     ph3 = sort(runif(5, 1, 100))
>                     )### reshape this to give a column indicating group
>   df2 <- with(df1,
>           as.data.frame(cbind( c(ph1, ph2, ph3),
>                               c(e1, e2, e3),
>                               rep(seq(3), each=5) )
>                         ))
>   colnames(df2) <- c("ph","maltose_in_mg","team")
>   df2$team <- as.factor(df2$team)
>   library(ggplot2)
>   ggplot(df2, aes(x=ph, y=maltose_in_mg, col=team)) + geom_line()
>
> Since I am still learning both R and ggplot2, I don't know how to proceed
> beyond what I have included here.

It's good form to mention that this was cross posted on StackOverflow: 
http://stackoverflow.com/q/19037565/892313

The comments there indicated that what you were trying to do (and what 
was not working) was not clear, and it has not been made any clearer in 
this duplicate. I gave a stab in the dark that you were looking for 
scale_x_continuous(limits=c(5, 9)), but that is a wild guess.

> Thanks,
>
> ~Caitlin
>
> 	[[alternative HTML version deleted]]
>

-- 
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University



More information about the R-help mailing list