mon
mon

Reputation: 17

Issues plotting multiple columns into a single plot

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.

Upvotes: 0

Views: 35

Answers (1)

Dij
Dij

Reputation: 1378

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")

Upvotes: 1

Related Questions