0

I used this link to find some code to plot multiple columns into one plot, but when I tried using the code I get a plot with everything but the data points and this error message

"geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?"

original data

enter image description here

converted data

enter image description here

the code I used:

df <- melt(Cooks_Farm_Cations_2017, id.vars = 'Site', variable.name = "Cation")

pa1<-ggplot(df, mapping=aes(Site,value)) + geom_line(aes(color=Cation))+ylab("mg/L")

My goal is to get a line plot of my 4 cations(y) for each sample site (x). Any help would be greatly appreciated.

3
  • 1
    try adding group = Cation like so: geom_line(aes(color=Cation, group = Cation)). If that doesn't work, use geom_line(aes(color=Cation), group = 1) Commented May 8, 2020 at 0:44
  • 1
    Fixed! Thank you! Commented May 8, 2020 at 0:50
  • 1
    I put the information in an answer--go ahead and accept it so others with the same question can make use of yours--thanks! Commented May 8, 2020 at 0:56

1 Answer 1

1

To draw parallel coordinates, you can make use of geom_line's group aesthetic

ggplot(df, mapping=aes(Site,value)) + 
  geom_line(aes(color=Cation, group = Cation)) + 
  ylab("mg/L")
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.