1

So I have a large data set which is entitled Site.377 On the x-axis I want the time which is in the X column and then the other 4 columns are entitled Results1, Results2, and Results3. I want to put them all on the same graph to compare how Results1 through 3 compare with each other over time.

What I currently did is:

library(ggplot2)
p <- ggplot(Site.377, aes(x=X, y = Results1) #This was just an attempt to get one of them to post
p + geom_line()

When I would do this, the resulting plot would just have all of the numerical values smushed together and stacked to the side. Seems like a column of numbers overlapped.

Any help would be greatly appreciated.

 X  Results1 Results2
 1     0       .23
 2    .83       0
 3    .56      .62
 4     0       .11
4
  • 1
    Can you provide a sample of your data by posting the output of dput(head(Site.377)). reshape2::melt before plotting and adding colour to aes is probably what you want to do similar to stackoverflow.com/questions/21616688/… Commented Feb 28, 2014 at 2:12
  • The amount of data in the set is far too large to post the results in dput(head(Site.377)). I just tried: ggplot(Site.377, aes(x=X, y=Results1)) + geom_line(colour="black") and had the same results. I may have misinterpreted what you said though. Commented Feb 28, 2014 at 2:20
  • Can you provide just first few columns of the data then? Like dput(head(Site.377[1:10])). Or create data that has the same characteristics and creates the same issue. I'm guessing something like this will work dfm <- melt(Site.377, id.vars = "X"); ggplot(dfm, aes(x = X, y = value, colour = variable)) + geom_line() Commented Feb 28, 2014 at 2:25
  • I made an edit with a little bit of a sample. It also should be noted that there are columns in this data set that I don't want to grab like a column called "Full.Profile" which is not needed and may be irrelevant to any discussion here. Commented Feb 28, 2014 at 2:36

1 Answer 1

4

Any columns you don't want you can just leave out by subsetting Site.377 before you melt it. Or subset based on variable after you melt it

Lucky guess in the comments :)

library(ggplot2)
library(reshape2)


dfm <- melt(Site.377, id.vars = "X")

p <- ggplot(dfm, aes(x = X, y = value, colour = variable))
p + geom_line()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.