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.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
mon
  • 17
  • 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)` – Dij May 08 '20 at 00:44
  • 1
    Fixed! Thank you! – mon May 08 '20 at 00: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! – Dij May 08 '20 at 00:56

1 Answers1

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")
Dij
  • 1,318
  • 1
  • 7
  • 13