Connecting Individual Observations across Trials

Hello, I am trying to make a graph in R that plots the bag time (s) against the number of trials. I can't figure out how to connect individual points across the trails. By that, I mean that one individual ran anywhere from 1 trial up to 11. For the individuals that ran more than 1 trial, I need a line to follow their performance through all of their trials. Is this possible in R?

My code to create the points can be found below. This plots the points of all trials across all individuals, however, I am stumped on how to get lines to connect the points of each individual across their trials. Thank you!

p2$Bag.Time.Trial <- factor(p2$Bag.Time.Trial)
p3<-subset(p2,p2$Bag.Time.s!="" & Sex!="F?" & Sex!="" & Species.Current=="Pln" & Age=="A")
ggplot(data= p3) +
geom_point(mapping=aes(x= Bag.Time.Trial, y= Bag.Time.s))

Bag.Time.s vs Trial #

With a reproducible example including some data to work with, it would be easier to give you a tested response, but here's an untested one:

ggplot(data= p3, mapping=aes(x= Bag.Time.Trial, y= Bag.Time.s, group = your_individual_column)) +
geom_point() + geom_line()

Maybe.

Hi ron, I believe that worked! The data file was imported from excel and is a huge data set, I wasn't entirely sure how to share it. This is what I got from that code and it looks like it did what I needed it to. I'm wondering if there is any way to make it look a little cleaner.

Bag time vs Trial with Line

I'd be tempted to try colouring by individuals, but without having a legend as there are too many individuals and maybe make the lines skinnier

ggplot(data= p3, mapping=aes(x= Bag.Time.Trial, y= Bag.Time.s, colour = your_individual_column)) +
geom_point() + geom_line(size=0.25)

(using colour, or fill, implies grouping by that variable too, I believe).

Or maybe colour by some other possibly informative variable (eg something that groups individuals, such as gender or age), and then you would colour by that variable and group by individual.

1 Like

Hi, so that did work and it looked pretty great. How would I add an overall trend line to this graph? I'm looking for something that would show the overall "population trend" based on the average behavior of the individuals.

My current code is:

#repeatability graph with Pmg (Knee Time)
p2$Knee.Time.Trial <- factor(p2$Knee.Time.Trial)
p3<-subset(p2,p2$Knee.Time.s!="" & Sex!="F?" & Sex!="" & Species.Current=="Pmg" & Age=="A" & Recapture.Trial!="N")
ggplot(data= p3, mapping=aes(x= Knee.Time.Trial, y= Knee.Time.s, color= MouseID, group = MouseID))+
geom_point()+
geom_line()+
ggtitle("Pmg") + xlab("Trial Number") + ylab("Knee Time (s)") +
theme_bw()+
theme(legend.position = "none")

Can you please share a small part of the data set in a copy-paste friendly format?

In case you don't know how to do it, there are many options, which include:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

I hope I did this right? Took the first 100 rows for the variables found below

tibble::tribble(
~MouseID, ~Bag.Time.s, ~Bag.Time.Trial, ~Recapture.Trial, ~Knee.Time.s, ~Knee.Time.Trial,
21L, 0, 1L, "Y", 30, 1L,
21L, 3.93, 2L, "Y", 28.44, 2L,
21L, 27.5, 3L, "Y", 23.5, 3L,
21L, 0.74, 4L, "Y", 22.91, 4L,
21L, 14.11, 5L, "Y", 1.35, 5L,
21L, 5.21, 6L, "Y", 1.94, 6L,
34L, 0, 1L, "N", 0, 1L,
56L, 18, 1L, "Y", 0, 1L,
56L, 0, 2L, "Y", 12, 2L,
56L, 0, 3L, "Y", 19.87, 3L,
56L, 0, 4L, "Y", 8, 4L,
56L, 0, 5L, "Y", 0, 5L,
78L, 1, 1L, "Y", 23, 1L,
78L, 0, 2L, "Y", 12.18, 2L,
78L, 2, 3L, "Y", 3, 3L,
78L, 0, 4L, "Y", 22, 4L,
78L, 0, 5L, "Y", NA, 5L,
78L, 20.81, 6L, "Y", 24.21, 6L,
78L, 0, 7L, "Y", 7.09, 7L,
78L, 0, 8L, "Y", 28.26, 8L,
78L, 0, 9L, "Y", 23.87, 9L,
78L, 5.56, 10L, "Y", 27.14, 10L,
78L, 0, 11L, "Y", 12.58, 11L,
95L, 0, 1L, "N", 18.38, 1L,
358L, 0, 1L, "N", 0.7, 1L,
364L, NA, 1L, "N", NA, 1L,
374L, 4.3, 1L, "N", 3.16, 1L,
860L, 21.95, 1L, "N", 7.15, 1L,
910L, 1, 1L, "Y", 1, 1L,
910L, 0, 2L, "Y", 0, 2L,
910L, 3.21, 3L, "Y", 2.03, 3L,
910L, 0, 4L, "Y", 6.03, 4L,
910L, 0, 5L, "Y", 0, 5L,
910L, 0, 6L, "Y", 7.18, 6L,
1112L, 1, 1L, "N", 4, 1L,
1314L, 0, 1L, "N", 0, 1L,
1410L, 0, 1L, "N", 0, 1L,
1516L, 0, 1L, "Y", 20, 1L,
1516L, 4.03, 2L, "Y", 6.09, 2L,
1718L, 0, 1L, "N", 29, 1L,
1730L, 27.94, 1L, "N", 29.11, 1L,
1920L, 22, 1L, "Y", 26, 1L,
1920L, 0, 2L, "Y", 27, 2L,
1920L, 0, 3L, "Y", 5.37, 3L,
2122L, 21, 1L, "Y", 24, 1L,
2122L, 0, 2L, "Y", 28.11, 2L,
2122L, 0, 3L, "Y", 4, 3L,
2324L, 11.36, 1L, "N", 30, 1L,
2526L, 0, 1L, "N", 0.88, 1L,
2827L, 0, 1L, "Y", 19, 1L,
2827L, 2, 2L, "Y", 22.19, 2L,
2827L, 0, 3L, "Y", 12.73, 3L,
2827L, 0, 4L, "Y", 6.85, 4L,
2827L, 0, 5L, "Y", 0.97, 5L,
2930L, 1, 1L, "Y", 21.62, 1L,
2930L, 0, 2L, "Y", 0, 2L,
2930L, 0, 3L, "Y", NA, 3L,
2930L, 0, 4L, "Y", 3.28, 4L,
2930L, 4.93, 5L, "Y", 10.66, 5L,
3132L, 0, 1L, "N", 30, 1L,
3334L, 1.8, 1L, "N", 0, 1L,
3536L, 2.21, 1L, "N", 23.75, 1L,
3635L, 0, 1L, "Y", 5.85, 1L,
3635L, 4.44, 2L, "Y", 3.47, 2L,
3635L, 15.95, 3L, "Y", 0.57, 3L,
3738L, 0, 1L, "Y", 0, 1L,
3738L, 0, 2L, "Y", 2.52, 2L,
3738L, 0, 3L, "Y", 26, 3L,
3738L, 0, 4L, "Y", NA, 4L,
3738L, 0, 5L, "Y", NA, 5L,
3738L, 0, 6L, "Y", NA, 6L,
3940L, 0, 1L, "N", 0, 1L,
4080L, 0.69, 1L, "Y", 0.46, 1L,
4080L, 0, 2L, "Y", 0, 2L,
4142L, 1, 1L, "N", 9, 1L,
4344L, 0, 1L, "Y", 9, 1L,
4344L, 1, 2L, "Y", 10, 2L,
4344L, 0, 3L, "Y", NA, 3L,
4344L, 0, 4L, "Y", 0.68, 4L,
4546L, 0, 1L, "Y", 0, 1L,
4546L, 0, 2L, "Y", 2.19, 2L,
4546L, 0, 3L, "Y", 0, 3L,
4546L, 0, 4L, "Y", 0, 4L,
4748L, 0, 1L, "N", 0, 1L,
4950L, 6, 1L, "N", 7, 1L,
5152L, 0, 1L, "Y", 4, 1L,
5152L, 17, 2L, "Y", 0, 2L,
5152L, 0, 3L, "Y", 24.47, 3L,
5152L, 0, 4L, "Y", 16.88, 4L,
5152L, 0, 5L, "Y", 15.23, 5L,
5152L, 0, 6L, "Y", 27.36, 6L,
5152L, 0, 7L, "Y", 24.27, 7L,
5152L, 0, 8L, "Y", 10.97, 8L,
5152L, NA, 9L, "Y", NA, 9L,
5354L, 0, 1L, "Y", 20.55, 1L,
5354L, 0, 2L, "Y", 6.94, 2L,
5556L, 0, 1L, "Y", 1, 1L,
5556L, 1, 2L, "Y", 0, 2L,
5556L, 0, 3L, "Y", 19.84, 3L,
5556L, 0.6, 4L, "Y", 0.91, 4L
)

A few observations of all the variables used in your code for each MouseID would be enough to make a minimal example.

Is this what you are trying to do?

library(tidyverse)

p3 <- tibble::tribble(
    ~MouseID, ~Bag.Time.s, ~Bag.Time.Trial, ~Recapture.Trial, ~Knee.Time.s, ~Knee.Time.Trial,
    21L, 0, 1L, "Y", 30, 1L,
    21L, 3.93, 2L, "Y", 28.44, 2L,
    21L, 27.5, 3L, "Y", 23.5, 3L,
    21L, 0.74, 4L, "Y", 22.91, 4L,
    21L, 14.11, 5L, "Y", 1.35, 5L,
    21L, 5.21, 6L, "Y", 1.94, 6L,
    34L, 0, 1L, "N", 0, 1L,
    56L, 18, 1L, "Y", 0, 1L,
    56L, 0, 2L, "Y", 12, 2L,
    56L, 0, 3L, "Y", 19.87, 3L,
    56L, 0, 4L, "Y", 8, 4L,
    56L, 0, 5L, "Y", 0, 5L,
    78L, 1, 1L, "Y", 23, 1L,
    78L, 0, 2L, "Y", 12.18, 2L,
    78L, 2, 3L, "Y", 3, 3L,
    78L, 0, 4L, "Y", 22, 4L,
    78L, 0, 5L, "Y", NA, 5L,
    78L, 20.81, 6L, "Y", 24.21, 6L,
    78L, 0, 7L, "Y", 7.09, 7L,
    78L, 0, 8L, "Y", 28.26, 8L,
    78L, 0, 9L, "Y", 23.87, 9L,
    78L, 5.56, 10L, "Y", 27.14, 10L,
    78L, 0, 11L, "Y", 12.58, 11L,
    95L, 0, 1L, "N", 18.38, 1L,
    358L, 0, 1L, "N", 0.7, 1L,
    364L, NA, 1L, "N", NA, 1L,
    374L, 4.3, 1L, "N", 3.16, 1L,
    860L, 21.95, 1L, "N", 7.15, 1L,
    910L, 1, 1L, "Y", 1, 1L,
    910L, 0, 2L, "Y", 0, 2L,
    910L, 3.21, 3L, "Y", 2.03, 3L,
    910L, 0, 4L, "Y", 6.03, 4L,
    910L, 0, 5L, "Y", 0, 5L,
    910L, 0, 6L, "Y", 7.18, 6L,
    1112L, 1, 1L, "N", 4, 1L,
    1314L, 0, 1L, "N", 0, 1L,
    1410L, 0, 1L, "N", 0, 1L,
    1516L, 0, 1L, "Y", 20, 1L,
    1516L, 4.03, 2L, "Y", 6.09, 2L,
    1718L, 0, 1L, "N", 29, 1L,
    1730L, 27.94, 1L, "N", 29.11, 1L,
    1920L, 22, 1L, "Y", 26, 1L,
    1920L, 0, 2L, "Y", 27, 2L,
    1920L, 0, 3L, "Y", 5.37, 3L,
    2122L, 21, 1L, "Y", 24, 1L,
    2122L, 0, 2L, "Y", 28.11, 2L,
    2122L, 0, 3L, "Y", 4, 3L,
    2324L, 11.36, 1L, "N", 30, 1L,
    2526L, 0, 1L, "N", 0.88, 1L,
    2827L, 0, 1L, "Y", 19, 1L,
    2827L, 2, 2L, "Y", 22.19, 2L,
    2827L, 0, 3L, "Y", 12.73, 3L,
    2827L, 0, 4L, "Y", 6.85, 4L,
    2827L, 0, 5L, "Y", 0.97, 5L,
    2930L, 1, 1L, "Y", 21.62, 1L,
    2930L, 0, 2L, "Y", 0, 2L,
    2930L, 0, 3L, "Y", NA, 3L,
    2930L, 0, 4L, "Y", 3.28, 4L,
    2930L, 4.93, 5L, "Y", 10.66, 5L,
    3132L, 0, 1L, "N", 30, 1L,
    3334L, 1.8, 1L, "N", 0, 1L,
    3536L, 2.21, 1L, "N", 23.75, 1L,
    3635L, 0, 1L, "Y", 5.85, 1L,
    3635L, 4.44, 2L, "Y", 3.47, 2L,
    3635L, 15.95, 3L, "Y", 0.57, 3L,
    3738L, 0, 1L, "Y", 0, 1L,
    3738L, 0, 2L, "Y", 2.52, 2L,
    3738L, 0, 3L, "Y", 26, 3L,
    3738L, 0, 4L, "Y", NA, 4L,
    3738L, 0, 5L, "Y", NA, 5L,
    3738L, 0, 6L, "Y", NA, 6L,
    3940L, 0, 1L, "N", 0, 1L,
    4080L, 0.69, 1L, "Y", 0.46, 1L,
    4080L, 0, 2L, "Y", 0, 2L,
    4142L, 1, 1L, "N", 9, 1L,
    4344L, 0, 1L, "Y", 9, 1L,
    4344L, 1, 2L, "Y", 10, 2L,
    4344L, 0, 3L, "Y", NA, 3L,
    4344L, 0, 4L, "Y", 0.68, 4L,
    4546L, 0, 1L, "Y", 0, 1L,
    4546L, 0, 2L, "Y", 2.19, 2L,
    4546L, 0, 3L, "Y", 0, 3L,
    4546L, 0, 4L, "Y", 0, 4L,
    4748L, 0, 1L, "N", 0, 1L,
    4950L, 6, 1L, "N", 7, 1L,
    5152L, 0, 1L, "Y", 4, 1L,
    5152L, 17, 2L, "Y", 0, 2L,
    5152L, 0, 3L, "Y", 24.47, 3L,
    5152L, 0, 4L, "Y", 16.88, 4L,
    5152L, 0, 5L, "Y", 15.23, 5L,
    5152L, 0, 6L, "Y", 27.36, 6L,
    5152L, 0, 7L, "Y", 24.27, 7L,
    5152L, 0, 8L, "Y", 10.97, 8L,
    5152L, NA, 9L, "Y", NA, 9L,
    5354L, 0, 1L, "Y", 20.55, 1L,
    5354L, 0, 2L, "Y", 6.94, 2L,
    5556L, 0, 1L, "Y", 1, 1L,
    5556L, 1, 2L, "Y", 0, 2L,
    5556L, 0, 3L, "Y", 19.84, 3L,
    5556L, 0.6, 4L, "Y", 0.91, 4L
)
p3 %>% 
    mutate(MouseID = factor(MouseID)) %>% 
    ggplot(mapping = aes(x = Knee.Time.Trial, y = Knee.Time.s)) +
    geom_point(aes(color = MouseID, group = MouseID)) +
    geom_line(aes(color = MouseID, group = MouseID)) +
    geom_smooth(method = "lm", linetype = "dashed") +
    ggtitle("Pmg") + xlab("Trial Number") + ylab("Knee Time (s)") +
    theme_bw() +
    theme(legend.position = "none")

Yes, that is what I'm trying to do. But how do I apply that to the code I have above with all the subsetting and such?

The code in my example is applied to the p3 dataframe so you just execute your subseting and then use the code to plot the dataframe.

I ran this exact code:

#repeatability graph with Pmg (Knee Time)
p2$Knee.Time.Trial <- factor(p2$Knee.Time.Trial)
p3<-subset(p2,p2$Knee.Time.s!="" & Sex!="F?" & Sex!="" & Species.Current=="Pmg" & Age=="A" & Recapture.Trial!="N")
p3 %>%
mutate(MouseID = factor(MouseID)) %>%
ggplot(mapping = aes(x = Knee.Time.Trial, y = Knee.Time.s)) +
geom_point(aes(color = MouseID, group = MouseID)) +
geom_line(aes(color = MouseID, group = MouseID)) +
geom_smooth(method = "lm", linetype = "dashed") +
ggtitle("Pmg") + xlab("Trial Number") + ylab("Knee Time (s)") +
theme_bw() +
theme(legend.position = "none")

and it gave me this:

Can you show sample data after the subsetting steps? Are you sure your subsetting steps are correct? it seems like you are getting not enough data points to get a trend.

Ideally, try to provide a proper REPRoducible EXample (reprex) illustrating your issue, that would make helping you much easier.

I'm really struggling trying to figure out how to share the data after the subset... I have this "p3" window in R that has the spreadsheet after the subset but I have no idea how to share it. At this point I'm reading a bunch of different of these pages and I have no idea what any of it means and I'm getting so frustrated I could literally cry. This shouldn't be this difficult, I'm an R newbie

Take a deep breath and calmly read the reprex guide I gave you, it is actually not that hard, you'll see.

This is p3 after the subset. All data seem to be correct

Knee.Time.s MouseID Knee.Time.Trial
568 7.00 16CH310 1
569 6.00 16CH310 2
573 0.00 16CH313 1
574 0.00 16CH313 2
616 30.00 16CH601 1
617 18.00 16CH601 2
621 15.00 16CH604 1
622 22.00 16CH604 2
623 11.00 16CH604 3
628 20.00 16CH606 1
629 0.00 16CH606 2
630 29.00 16CH606 3
661 6.00 16CH625 1
662 7.00 16CH625 2
898 26.00 16SC302 1
899 12.00 16SC302 2
901 26.00 16SC304 1
902 29.00 16SC304 2
903 11.00 16SC305 1
904 12.00 16SC305 2
905 10.00 16SC306 1
906 26.00 16SC306 2
941 27.00 16SC601 1
942 25.00 16SC601 2
944 28.00 16SC603 1
945 28.00 16SC603 2
946 28.00 16SC604 1
947 22.00 16SC604 2
949 24.00 16SC606 1
950 28.00 16SC606 2
951 25.00 16SC607 1
952 28.00 16SC607 2
1744 28.76 MZ11410 1
1745 28.76 MZ11410 2

or this using dput:

structure(list(MouseID = structure(c(52L, 52L, 55L, 55L, 93L,
93L, 96L, 96L, 96L, 98L, 98L, 98L, 116L, 116L, 316L, 316L, 318L,
318L, 319L, 319L, 320L, 320L, 355L, 355L, 357L, 357L, 358L, 358L,
360L, 360L, 361L, 361L, 1360L, 1360L), .Label = c("", "101102",
"103104", "105106", "107108", "109110", "111112", "1112", "113114",
"115116", "117118", "119120", "121122", "123124", "125126", "127128",
"129130", "131132", "1314", "133134", "135136", "137138", "139140",
"1410", "141142", "141285", "143144", "145146", "147148", "149150",
"151152", "1516", "152152", "153154", "155156", "157158", "159160",
"161162", "163164", "165166", "167168", "169170", "16CH301",
"16CH302", "16CH303", "16CH304", "16CH305", "16CH306", "16CH307",
"16CH308", "16CH309", "16CH310", "16CH311", "16CH312", "16CH313",
"16CH314", "16CH315", "16CH316", "16CH317", "16CH318", "16CH319",
"16CH320", "16CH321", "16CH322", "16CH323", "16CH324", "16CH325",
"16CH326", "16CH327", "16CH328", "16CH329", "16CH330", "16CH331",
"16CH332", "16CH333", "16CH334", "16CH335", "16CH336", "16CH337",
"16CH338", "16CH339", "16CH340", "16CH341", "16CH342", "16CH343",
"16CH344", "16CH345", "16CH346", "16CH347", "16CH348", "16CH349",
"16CH354", "16CH601", "16CH602", "16CH603", "16CH604", "16CH605",
"16CH606", "16CH607", "16CH608", "16CH609", "16CH611", "16CH612",
"16CH613", "16CH614", "16CH615", "16CH616", "16CH617", "16CH618",
"16CH619", "16CH620", "16CH621", "16CH622", "16CH623", "16CH624",
"16CH625", "16CH626", "16CH627", "16CH628", "16CH629", "16CH630",
"16CH631", "16CH632", "16CH633", "16CH634", "16CH635", "16CH636",
"16CH637", "16CH638", "16CH639", "16CH640", "16CH641", "16CH642",
"16CH643", "16DA001", "16DA002", "16DA003", "16DA004", "16DA005",
"16DA006", "16DA007", "16DA008", "16DA009", "16DA010", "16DA011",
"16DA012", "16DA013", "16DA014", "16DA015", "16DA016", "16DA017",
"16DA018", "16DA019", "16DA020", "16DA021", "16DA022", "16DA023",
"16DA024", "16DA025", "16DA026", "16DA030", "16OT001", "16OT002",
"16OT003", "16OT005", "16OT006", "16OT007", "16OT008", "16OT009",
"16OT010", "16OT011", "16OT012", "16OT013", "16OT014", "16OT015",
"16OT016", "16OT017", "16OT018", "16OT019", "16OT021", "16OT022",
"16OT023", "16OT024", "16OT025", "16OT026", "16OT027", "16OT028",
"16OT029", "16OT030", "16OT031", "16OT032", "16OT033", "16OT034",
"16OT035", "16OT036", "16OT037", "16OT038", "16OT039", "16OT040",
"16OT041", "16OT042", "16OT043", "16OT044", "16OT045", "16OT046",
"16OT047", "16OT048", "16OT049", "16OT050", "16OT051", "16OT052",
"16OT053", "16OT054", "16OT055", "16OT056", "16OT057", "16OT058",
"16OT059", "16OT060", "16OT061", "16OT062", "16OT063", "16OT064",
"16OT065", "16OT066", "16OT067", "16OT068", "16OT069", "16OT070",
"16OT071", "16OT072", "16OT073", "16OT074", "16OT075", "16OT076",
"16OT077", "16OT078", "16OT079", "16OT080", "16OT081", "16OT082",
"16OT083", "16OT084", "16OT085", "16OT086", "16OT087", "16OT088",
"16OT089", "16OT090", "16OT091", "16OT092", "16OT093", "16OT094",
"16OT095", "16OT096", "16OT097", "16OT098", "16OT099", "16OT100",
"16OT101", "16OT102", "16OT103", "16OT104", "16OT105", "16OT106",
"16OT107", "16OT108", "16OT109", "16OT110", "16OT111", "16OT112",
"16OT113", "16OT114", "16OT115", "16OT116", "16OT117", "16OT118",
"16OT119", "16OT120", "16OT121", "16OT122", "16OT123", "16OT124",
"16OT125", "16OT126", "16OT127", "16OT128", "16OT129", "16OT130",
"16OT131", "16OT132", "16OT133", "16OT134", "16OT135", "16OT136",
"16OT137", "16OT138", "16OT139", "16OT140", "16OT141", "16OT142",
"16OT143", "16OT144", "16OT145", "16OT146", "16OT147", "16OT148",
"16OT149", "16OT150", "16OT151", "16OT152", "16OT153", "16OT154",
"16OT260", "16SC301", "16SC302", "16SC303", "16SC304", "16SC305",
"16SC306", "16SC307", "16SC308", "16SC309", "16SC310", "16SC311",
"16SC312", "16SC313", "16SC314", "16SC315", "16SC316", "16SC317",
"16SC318", "16SC319", "16SC320", "16SC321", "16SC322", "16SC323",
"16SC324", "16SC325", "16SC326", "16SC327", "16SC328", "16SC329",
"16SC330", "16SC331", "16SC332", "16SC333", "16SC334", "16SC335",
"16SC336", "16SC337", "16SC338", "16SC339", "16SC340", "16SC601",
"16SC602", "16SC603", "16SC604", "16SC605", "16SC606", "16SC607",
"16SC608", "16SC609", "16SC610", "16SC611", "16SC612", "16SC613",
"16SC614", "16SC615", "16SC616", "16SC617", "16SC618", "16SC619",
"16SC620", "16SC621", "16SC622", "16SC623", "16SC624", "16SC625",
"16SC626", "16SC627", "16SC628", "16SC629", "16SC630", "16SC631",
"16SC632", "16SC633", "16SC634", "16SC635", "16SC636", "16SC637",
"16SC638", "16SC639", "16SC640", "16SC641", "16SC642", "171172",
"1718", "1730", "173174", "175176", "177178", "179180", "17CH301",
"17CH302", "17CH303", "17CH304", "17CH305", "17CH306", "17CH307",
"17CH308", "17CH309", "17CH310", "17CH311", "17CH312", "17CH313",
"17CH323", "17CH324", "17CH325", "17CH326", "17CH327", "17CH328",
"17CH331", "17CH332", "17CH333", "17CH334", "17CH335", "17CH336",
"17CH337", "17CH338", "17CH339", "17CH601", "17CH602", "17CH603",
"17CH604", "17CH605", "17CH606", "17CH607", "17CH615", "17CH616",
"17CH617", "17CH618", "17CH619", "17CH620", "17CH621", "17CH622",
"17CH623", "17CH624", "17CH625", "17CH626", "17CH627", "17CH628",
"17CH629", "17CH630", "17CH631", "17CH632", "17CH633", "17CH635",
"17CH636", "17CH637", "17CH638", "17CH639", "17CH640", "17CH641",
"17CH642", "17CH643", "17CH901", "17CH902", "17CH903", "17CH904",
"17CH905", "17CH906", "17CH907", "17CH908", "17CH909", "17CH910",
"17CH911", "17CH912", "17CH913", "17CH914", "17CH915", "17CH916",
"17CH917", "17CH918", "17CH919", "17CH920", "17CH921", "17CH922",
"17CH923", "17CH924", "17DA001", "17DA002", "17DA003", "17DA004",
"17DA005", "17DA006", "17DA007", "17DA051", "17DA052", "17DA053",
"17DA054", "17DA055", "17DA056", "17DA057", "17DA058", "17DA059",
"17DA060", "17DA061", "17DA062", "17DA063", "17DA064", "17DA065",
"17DA066", "17OT001", "17OT002", "17OT003", "17OT026", "17OT027",
"17OT028", "17OT029", "17OT030", "17OT031", "17OT032", "17OT033",
"17OT034", "17OT035", "17OT036", "17OT037", "17OT038", "17OT039",
"17OT040", "17OT041", "17OT042", "17OT043", "17OT044", "17OT045",
"17OT046", "17OT047", "17OT048", "17OT049", "17OT050", "17OT051",
"17OT052", "17OT053", "17OT054", "17OT055", "17OT056", "17OT057",
"17OT058", "17OT059", "17OT060", "17OT061", "17OT062", "17OT063",
"17OT064", "17OT065", "17OT066", "17OT067", "17OT068", "17OT069",
"17OT070", "17OT071", "17SC301", "17SC302", "17SC303", "17SC304",
"17SC305", "17SC306", "17SC307", "17SC308", "17SC309", "17SC310",
"17SC311", "17SC312", "17SC313", "17SC314", "17SC315", "17SC316",
"17SC317", "17SC318", "17SC319", "17SC328", "17SC329", "17SC330",
"17SC331", "17SC332", "17SC333", "17SC334", "17SC335", "17SC336",
"17SC337", "17SC338", "17SC339", "17SC340", "17SC341", "17SC342",
"17SC343", "17SC344", "17SC345", "17SC601", "17SC602", "17SC603",
"17SC604", "17SC605", "17SC606", "17SC607", "17SC608", "17SC609",
"17SC610", "17SC611", "17SC612", "17SC613", "17SC614", "17SC615",
"17SC616", "17SC617", "17SC658", "17SC659", "17SC660", "17SC661",
"17SC662", "17SC663", "17SC664", "17SC665", "17SC666", "17SC667",
"17SC668", "17SC669", "17SC670", "17SC671", "17SC672", "17SC673",
"17SC674", "17SC675", "17SC676", "17SC677", "17SC678", "17SC679",
"17SC680", "17SC681", "17SC682", "17SC683", "17SC684", "17SC685",
"181182", "183184", "185186", "187188", "187306", "189190", "18CH001",
"18CH002", "18CH003", "18CH004", "18CH005", "18CH006", "18CH007",
"18CH008", "18CH009", "18CH010", "18CH011", "18CH012", "18CH013",
"18CH014", "18CH100", "18CH101", "18CH102", "18CH103", "18CH104",
"18CH105", "18CH106", "18CH107", "18CH108", "18CH109", "18CH401",
"18CH402", "18CH403", "18CH404", "18CH405", "18CH406", "18CH407",
"18CH408", "18CH409", "18CH410", "18CH411", "18CH412", "18CH413",
"18CH414", "18CH415", "18CH416", "18CH417", "18CH418", "18CH419",
"18CH420", "18CH421", "18CH422", "18CH423", "18CH424", "18CH425",
"18CH426", "18CH427", "18CH428", "18CH429", "18CH701", "18CH702",
"18CH703", "18CH704", "18CH705", "18CH706", "18CH707", "18CH708",
"18CH709", "18CH710", "18CH711", "18CH712", "18CH713", "18CH714",
"18CH715", "18CH716", "18CH717", "18CH718", "18CH719", "18DA101",
"18DA102", "18DA103", "18DA104", "18DA105", "18DA106", "18DA107",
"18DA108", "18DA109", "18DA110", "18DA111", "18DA112", "18DA113",
"18DA114", "18DA115", "18DA116", "18DA117", "18DA118", "18DA119",
"18DA120", "18DA121", "18DA122", "18DA123", "18DA124", "18DA125",
"18DA126", "18DA127", "18DA128", "18DA129", "18DA130", "18DA131",
"18OT101", "18OT102", "18OT103", "18OT104", "18OT105", "18OT106",
"18OT107", "18OT108", "18OT109", "18OT110", "18OT111", "18OT112",
"18OT113", "18OT114", "18OT115", "18OT116", "18OT117", "18OT118",
"18OT119", "18OT120", "18OT121", "18OT122", "18OT123", "18OT124",
"18OT125", "18OT126", "18OT127", "18OT128", "18OT129", "18OT130",
"18OT131", "18OT132", "18OT133", "18OT134", "18OT135", "18OT136",
"18OT137", "18OT138", "18SC401", "18SC402", "18SC403", "18SC404",
"18SC405", "18SC406", "18SC407", "18SC408", "18SC409", "18SC410",
"18SC411", "18SC412", "18SC413", "18SC701", "18SC702", "18SC703",
"18SC704", "18SC705", "18SC706", "18SC707", "18SC708", "18SC709",
"18SC710", "18SC711", "18SC712", "18SC713", "18SC714", "18SC715",
"18SC716", "18SC717", "18SC718", "18SC719", "18SC720", "18SC721",
"18SC722", "18SC723", "18SC724", "18SC725", "18SC726", "18SC727",
"18SC728", "18SC729", "18SC730", "18SC731", "18SC732", "18SC733",
"18SC734", "18SC735", "18SC736", "191192", "1920", "193194",
"195196", "197198", "199200", "19DA201", "19DA202", "19DA204",
"19DA205", "19DA206", "19DA207", "19DA208", "19DA209", "19DA210",
"19DA211", "19DA212", "19DA213", "19DA214", "19DA215", "19SC?",
"19SC501", "19SC502", "19SC503", "19SC504", "19SC505", "19SC506",
"19SC507", "19SC508", "19SC509", "19SC510", "19SC511", "19SC512",
"19SC513", "19SC801", "19SC802", "19SC803", "19SC804", "19SC805",
"19SC806", "19SC807", "19SC808", "19SC809", "19SC810", "19SC811",
"19SC812", "19SC813", "19SC814", "19SC815", "19SC816", "19SC817",
"19SC818", "19SC819", "19SC820", "19SC821", "19SC822", "19SC823",
"19SC824", "19SC825", "19SC826", "19SC827", "19SC828", "19SC829",
"201202", "203204", "205206", "207209", "21", "210211", "2122",
"212213", "214215", "216217", "218219", "220221", "222223", "224225",
"226227", "226307", "228229", "230231", "232233", "2324", "234235",
"236237", "238239", "240241", "242243", "244245", "246247", "248249",
"250251", "252253", "2526", "254255", "256257", "258156", "259260",
"261262", "263264", "265266", "267268", "269270", "271272", "273274",
"275276", "277278", "279280", "281282", "2827", "283284", "286287",
"288289", "290291", "292293", "2930", "294295", "296297", "298299",
"300301", "302303", "304305", "308309", "310311", "312313", "3132",
"314315", "316317", "318319", "320321", "322323", "324325", "327328",
"329330", "332333", "3334", "334335", "336337", "338339", "34",
"340341", "342100", "343344", "345346", "347348", "349350", "351352",
"352375", "353354", "3536", "355356", "357358", "358", "359360",
"361362", "363364", "3635", "364", "365366", "367376", "369370",
"371372", "3738", "374", "375352", "377378", "379380", "381350",
"382383", "384385", "386387", "388389", "390391", "392393", "3940",
"394395", "396397", "398399", "400401", "402403", "404405", "406358",
"4080", "411414", "4142", "415443", "416419", "424439", "430435",
"431434", "4344", "438470", "440446", "451500", "452453", "454455",
"4546", "456457", "458459", "460461", "462463", "464465", "466467",
"468469", "471472", "473475", "4748", "476477", "478479", "480481",
"482483", "484485", "486487", "488489", "490491", "492493", "494495",
"4950", "496497", "498499", "5152", "5354", "5556", "56", "57326",
"5758", "5960", "6162", "6364", "6566", "6768", "6970", "7172",
"7374", "75100", "7677", "78", "7879", "8081", "8283", "8485",
"860", "86331", "8687", "8889", "9091", "910", "9293", "9495",
"95", "9697", "Chip.UMBS_6.24.2016_1", "Chip.UMBS_6.24.2016_2",
"Chip.UMBS_6.24.2016_3", "Chip.UMBS_6.24.2016_4", "Chip.UMBS_6.25.2016_1",
"Chip.UMBS_6.25.2016_2", "Chip.UMBS_6.27.2016_1", "Chip.UMBS_6.27.2016_2",
"Chip.UMBS_6.27.2016_3", "Chip.UMBS_6.30.2016_1", "Chip.UMBS_6.30.2016_2",
"Chip.UMBS_6.30.2016_3", "Chip.UMBS_7.03.2016_1", "Chip.UMBS_7.03.2016_2",
"Chip.UMBS_7.04.2016_1", "Chip.UMBS_7.04.2016_2", "Chip.UMBS_7.04.2016_3",
"Chip.UMBS_7.04.2016_4", "Chip.UMBS_7.04.2016_5", "Chip.UMBS_7.04.2016_6",
"Chip.UMBS_7.04.2016_7", "Chip.UMBS_7.04.2016_8", "Chip.UMBS_7.05.2016_1",
"Chip.UMBS_7.05.2016_2", "Chip.UMBS_7.05.2016_3", "Chip.UMBS_7.05.2016_4",
"Chip.UMBS_7.05.2016_5", "Chip.UMBS_7.05.2016_6", "Chip.UMBS_7.05.2016_7",
"Chip.UMBS_7.05.2016_8", "Chip.UMBS_7.07.2016_1", "Chip.UMBS_7.07.2016_2",
"Chip.UMBS_7.07.2016_3", "Chip.UMBS_7.07.2016_4", "Chip.UMBS_7.07.2016_5",
"Chip.UMBS_7.07.2016_6", "Chip.UMBS_7.12.2016_1", "Chip.UMBS_7.12.2016_2",
"Chip.UMBS_7.12.2016_3", "Chip.UMBS_7.12.2016_4", "Chip.UMBS_7.14.2016_1",
"Chip.UMBS_7.14.2016_2", "Chip.UMBS_7.15.2016_1", "Chip.UMBS_7.15.2016_2",
"Chip.UMBS_7.15.2016_3", "Chip.UMBS_7.18.2016_1", "Chip.UMBS_7.18.2016_2",
"Chip.UMBS_7.18.2016_3", "Chip.UMBS_7.19.2016_1", "Chip.UMBS_7.19.2016_2",
"Chip.UMBS_7.19.2016_3", "Chip.UMBS_7.21.2016_1", "Chip.UMBS_7.21.2016_2",
"Chip.UMBS_7.21.2016_3", "Chip.UMBS_7.21.2016_4", "Chip.UMBS_7.22.2016_1",
"Chip.UMBS_7.22.2016_2", "Chip.UMBS_7.25.2016_1", "Chip.UMBS_7.25.2016_2",
"Chip.UMBS_7.25.2016_3", "Chip.UMBS_7.26.2016_1", "Chip.UMBS_7.26.2016_2",
"Chip.UMBS_7.26.2016_3", "Chip.UMBS_8.02.2016_1", "Chip.UMBS_8.05.2016_1",
"Chip.UMBS_8.05.2016_2", "Chip.UMBS_8.05.2016_3", "Chip.UMBS_8.07.2016_1",
"Chip.UMBS_8.07.2016_2", "Chip.UMBS_8.07.2016_3", "Chip.UMBS_8.08.2016_1",
"DR1_5.24.2016_1", "DRF_10.01.2017_1", "DRF_10.01.2017_10", "DRF_10.01.2017_2",
"DRF_10.01.2017_3", "DRF_10.01.2017_4", "DRF_10.01.2017_5", "DRF_10.01.2017_6",
"DRF_10.01.2017_7", "DRF_10.01.2017_8", "DRF_10.01.2017_9", "DRF_5.23.17_1",
"DRF_9.30.2017_1", "DRF_9.30.2017_2", "DRF_9.30.2017_3", "DRF_9.30.2017_4",
"DRF_9.30.2017_5", "DRF_9.30.2017_6", "DRF_9.30.2017_7", "HNF82616",
"Hoffman_5.20.2016_1", "Hoffman_5.20.2016_2", "Hoffman_5.20.2016_3",
"Hoffman_5.20.2016_4", "Hoffman_5.20.2016_5", "Hoffman_5.20.2016_6",
"Hoffman_5.20.2016_7", "Hoffman_5.20.2016_8", "JRF_10.01.2017_1",
"JRF_10.01.2017_2", "JRF_5.24.17_1", "JRF_5.24.17_2", "JRF_5.24.17_3",
"JRF_5.24.17_4", "JRF_9.17.16_1", "JRF_9.17.16_10", "JRF_9.17.16_11",
"JRF_9.17.16_12", "JRF_9.17.16_2", "JRF_9.17.16_3", "JRF_9.17.16_4",
"JRF_9.17.16_5", "JRF_9.17.16_6", "JRF_9.17.16_7", "JRF_9.17.16_8",
"JRF_9.17.16_9", "JRF_9.30.2017_1", "JRF_9.30.2017_2", "JRF_9.30.2017_3",
"MZ11251", "MZ11252", "MZ11253", "MZ11254", "MZ11255", "MZ11256",
"MZ11257", "MZ11258", "MZ11259", "MZ11260", "MZ11261", "MZ11262",
"MZ11263", "MZ11264", "MZ11265", "MZ11266", "MZ11267", "MZ11268",
"MZ11269", "MZ11270", "MZ11271", "MZ11272", "MZ11273", "MZ11274",
"MZ11275", "MZ11276", "MZ11277", "MZ11278", "MZ11279", "MZ11286",
"MZ11287", "MZ11288", "MZ11289", "MZ11290", "MZ11290J", "MZ11291",
"MZ11292", "MZ11293", "MZ11294", "MZ11295", "MZ11296", "MZ11297",
"MZ11298", "MZ11299", "MZ11300", "MZ11301", "MZ11302", "MZ11303",
"MZ11304", "MZ11305", "MZ11306", "MZ11307", "MZ11308", "MZ11309",
"MZ11310", "MZ11311", "MZ11312", "MZ11313", "MZ11320", "MZ11321",
"MZ11322", "MZ11323", "MZ11324", "MZ11325", "MZ11326", "MZ11327",
"MZ11328", "MZ11329", "MZ11330", "MZ11331", "MZ11332", "MZ11333",
"MZ11334", "MZ11335", "MZ11336", "MZ11337", "MZ11338", "MZ11339",
"MZ11340", "MZ11341", "MZ11342", "MZ11343", "MZ11344", "MZ11345",
"MZ11346", "MZ11347", "MZ11348", "MZ11349", "MZ11350", "MZ11351",
"MZ11352", "MZ11353", "MZ11354", "MZ11355", "MZ11356", "MZ11357",
"MZ11358", "MZ11359", "MZ11360", "MZ11361", "MZ11362", "MZ11363",
"MZ11364", "MZ11365", "MZ11366", "MZ11367", "MZ11368", "MZ11369",
"MZ11370", "MZ11371", "MZ11372", "MZ11373", "MZ11374", "MZ11375",
"MZ11376", "MZ11377", "MZ11378", "MZ11379", "MZ11380", "MZ11381",
"MZ11382", "MZ11383", "MZ11384", "MZ11385", "MZ11386", "MZ11387",
"MZ11388", "MZ11389", "MZ11390", "MZ11391", "MZ11392", "MZ11393",
"MZ11394", "MZ11395", "MZ11396", "MZ11397", "MZ11398", "MZ11399",
"MZ11400", "MZ11401", "MZ11402", "MZ11403", "MZ11404", "MZ11405",
"MZ11406", "MZ11407", "MZ11408", "MZ11409", "MZ11410", "MZ11411",
"MZ11412", "MZ11413", "MZ11414", "MZ11415", "MZ11417", "MZ11418",
"MZ11420", "MZ11421", "MZ11422", "MZ11424", "MZ11425", "MZ11426",
"MZ11427", "MZ11428", "MZ11429", "MZ11430", "MZ11431", "MZ11432",
"MZ11433", "MZ11434", "MZ11435", "MZ11436", "MZ11437", "MZ11438",
"MZ11439", "MZ11441", "MZ11442", "MZ11443", "MZ11444", "MZ11445",
"MZ11446", "MZ11447", "MZ11448", "MZ11449", "MZ11450", "MZ11451",
"MZ11452", "MZ11453", "MZ11454", "MZ11455", "MZ11456", "MZ11457",
"MZ11458", "MZ11459", "RAGL_7.12.17_1", "Shrew.UMBS_7.12.2016_1",
"UMBS_7.12.2016_1", "UMBS_7.18.2016_1", "UMBS98_5.22.2016_1",
"WWR_7.15.17_1"), class = "factor"), Knee.Time.s = c(7, 6, 0,
0, 30, 18, 15, 22, 11, 20, 0, 29, 6, 7, 26, 12, 26, 29, 11, 12,
10, 26, 27, 25, 28, 28, 28, 22, 24, 28, 25, 28, 28.76, 28.76),
Knee.Time.Trial = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), class = "factor")), row.names = c(568L,
569L, 573L, 574L, 616L, 617L, 621L, 622L, 623L, 628L, 629L, 630L,
661L, 662L, 898L, 899L, 901L, 902L, 903L, 904L, 905L, 906L, 941L,
942L, 944L, 945L, 946L, 947L, 949L, 950L, 951L, 952L, 1744L,
1745L), class = "data.frame")

You are not getting the smooth line because the Knee.Time.Trial variable is of class "factor", if you convert it to numeric, you get the smoothing line.

library(tidyverse)
p3 <- data.frame(
        row.names = c("568","569","573","574","616",
                      "617","621","622","623","628","629","630","661",
                      "662","898","899","901","902","903","904","905",
                      "906","941","942","944","945","946","947","949",
                      "950","951","952","1744","1745"),
      Knee.Time.s = c(7,6,0,0,30,18,15,22,11,
                      20,0,29,6,7,26,12,26,29,11,12,10,26,27,25,28,
                      28,28,22,24,28,25,28,28.76,28.76),
          MouseID = as.factor(c("16CH310",
                                "16CH310","16CH313","16CH313","16CH601",
                                "16CH601","16CH604","16CH604","16CH604","16CH606",
                                "16CH606","16CH606","16CH625","16CH625",
                                "16SC302","16SC302","16SC304","16SC304",
                                "16SC305","16SC305","16SC306","16SC306","16SC601",
                                "16SC601","16SC603","16SC603","16SC604",
                                "16SC604","16SC606","16SC606","16SC607",
                                "16SC607","MZ11410","MZ11410")),
  Knee.Time.Trial = as.factor(c("1","2","1",
                                "2","1","2","1","2","3","1","2","3",
                                "1","2","1","2","1","2","1","2","1","2",
                                "1","2","1","2","1","2","1","2","1",
                                "2","1","2"))
)

p3 %>%
    mutate(Knee.Time.Trial = as.numeric(Knee.Time.Trial)) %>% 
    ggplot(mapping = aes(x = Knee.Time.Trial, y = Knee.Time.s)) +
    geom_point(aes(color = MouseID, group = MouseID)) +
    geom_line(aes(color = MouseID, group = MouseID)) +
    geom_smooth(method = "lm", linetype = "dashed") +
    ggtitle("Pmg") + 
    xlab("Trial Number") +
    ylab("Knee Time (s)") +
    theme_bw() +
    theme(legend.position = "none")
#> `geom_smooth()` using formula 'y ~ x'

After almost throwing my computer across the room, I went up to my boss and we figured that out. Thank you so much for your help on this. It's amazing how one tiny little issue like it being numeric vs factor can cause such pain haha.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.