Home:ALL Converter>Trying to create multiple lines chart Rstudio

Trying to create multiple lines chart Rstudio

Ask Time:2018-01-30T05:38:46         Author:dman

Json Formatter

Hi I am trying to create a multiple coloured line graph based on three lines.

Essentially I have data that identifies different people by the variable Person_Index. I want to create a plot with differently coloured lines for each Person_Index identity.

The following is a screen shot of the data structure

The following is a snippet of my code I am trying to accomplish this with. (Sorry I was having trouble with the formatting and so had to include it as an image)

Code snippet

However when I go to plot, I get this?

Plot output

It is plotting all of the points. But it is not separating them by the person_index ID's. What am I missing? And also how do I get Rstudio to return the trend line equation?

Author:dman,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48510424/trying-to-create-multiple-lines-chart-rstudio
erocoar :

In your loop, you aren't indexing the data by the person. So it is just plotting all the data again and again. You could do something like this:\n\nfor (i in 1:length(unique(PersonID_num))) {\n lines(Timestamp_num[PersonID_num==unique(PersonID_num)[i]], \n boundx[PersonID_num==unique(PersonID_num)[i]], type = \"b\", lwd = 1.5, lty = linetype[i], col = colors[i])\n}\n\n\nAlternatively, it might be more convenient to use ggplot2. There, you can specify a dataframe with your timestamps, boundx and people IDs and then do something along the lines of\n\nggplot(data, aes(x = Timestamp_num, y = boundx, color = PersonID_num)) + geom_line()\n",
2018-01-29T23:08:01
yy