I have a dataset like this that I have turned into a massive dendrogram using time series clustering:
DF<-structure(list(`Smith, Sumner` = c(" 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 1", " 1", " 1", " 1", " 2", " 3", " 7",
" 15", " 22", " 25", " 31", " 32", " 40", " 41", " 45", " 47",
" 48", " 48", " 49", " 49", " 49", " 49", " 49", " 49"), `Fizzle III, Joseph` = c(" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 5", " 6", " 7", " 9", " 9", " 11", " 21", " 25", " 33",
" 38", " 44", " 51", " 54", " 57", " 60", " 61", " 67", " 72",
" 73", " 73"), `johnson, Barry` = c(" 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 1", " 5", " 7",
" 11", " 12", " 17", " 20", " 21", " 24", " 25", " 28", " 28",
" 28", " 28", " 28", " 31", " 31", " 33", " 33", " 33"), `peanut, Mark` = c(" 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 1", " 2", " 5", "10", "18",
"22", "23", "27", "28", " 30", " 34", " 42", " 44", " 48", " 51",
" 62", " 64", " 65", " 66", " 67", " 68", " 73", " 75", " 76",
" 81", " 86", " 89", " 89", " 92", " 94", "102", "111", "118",
"133", "141", "146", "157", "158", "158", "158", "158", "158",
"158", "158"), `alpha, John A` = c(" 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 6", " 11", " 13", " 15", " 17", " 20", " 31",
" 35", " 41", " 46", " 53", " 59", " 69", " 87", " 91", " 93",
"103", "127", "133", "133", "133", "133", "133", "133", "133"
), `barry, Lloyd Alan` = c(" 0", " 0", " 0", " 1", " 2", " 2",
" 3", " 3", " 3", " 3", " 3", " 5", " 7", "11", "13", "18", " 23",
" 23", " 23", " 27", " 28", " 31", " 32", " 32", " 33", " 33",
" 33", " 33", " 33", " 33", " 33", " 33", " 33", " 33", " 33",
" 33", " 33", " 33", " 33", " 33", " 33", " 33", " 33", " 33",
" 33", " 33", " 33", " 33", " 33", " 33", " 33"), `smith, EK` = c(" 0",
" 0", " 2", " 3", " 3", " 3", " 4", " 6", " 6", " 6", " 6", " 6",
" 6", " 7", "14", "15", " 18", " 25", " 28", " 29", " 33", " 37",
" 45", " 49", " 51", " 54", " 61", " 65", " 65", " 70", " 75",
" 79", " 79", " 81", " 82", " 83", " 87", " 89", " 89", " 91",
" 91", " 91", " 91", " 93", " 95", " 95", " 98", " 98", " 99",
"100", "100"), `parvin, Eric David` = c(" 0", " 0", " 0", " 0",
" 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0", " 0",
" 0", " 0", " 4", " 6", " 6", " 6", " 6", " 6", " 6",
" 6", " 6", " 6", " 6", " 6", " 6", " 7", " 7", " 9",
" 10", " 10", " 10", " 10", " 10", " 10", " 10", " 10", " 10",
" 10", " 10", " 10", " 10", " 10", " 10", " 10", " 10", " 10"
), `Burgess, Gary` = c(" 0", " 0", " 0", " 1", " 1", " 1",
" 1", " 1", " 1", " 1", " 1", " 1", " 1", " 1", " 1", " 3", " 5",
" 5", " 5", " 6", " 7", " 7", " 8", " 8", " 8", " 9",
" 9", " 9", " 9", " 11", " 11", " 11", " 11", " 12", " 12",
" 14", " 14", " 15", " 15", " 17", " 17", " 17", " 18", " 18",
" 18", " 18", " 18", " 18", " 18", " 18", " 18"), `smith, john` = c(" 0",
" 0", " 0", " 0", " 1", " 1", " 3", " 6", " 6", " 6", " 8", " 8",
" 8", " 8", " 8", " 8", " 8", " 8", " 8", " 9", " 10", " 11",
" 13", " 14", " 16", " 16", " 17", " 18", " 18", " 19", " 20",
" 20", " 20", " 21", " 21", " 22", " 22", " 22", " 22", " 22",
" 22", " 22", " 22", " 22", " 22", " 22", " 22", " 22", " 22",
" 22", " 22")), row.names = c(NA, -51L), class = c("tbl_df",
"tbl", "data.frame"))
P.s. anyone know why it pastes so weird like that when I copy from RStudio? With giant spaces?
Anyhow, in the data, each column is a person (names should be scrambled) and the rows represent years, where a certain number of events happened each year. I've used time series clustering with the real data set (hundreds of columns) to create a dendrogram that groups the most similar columns together. I can access that grouping in a data frame that looks like this:
DF2<-structure(list(type_col = c("Smith, Sumner", "josephs, Joseph",
"smith, Barry", "johnson, Mark", "Peanut, John A", "smithy, Lloyd Alan",
"john, EK", "Amistad, Eric David", "Hotdog, Gary ", "Jones, SMith"
), cluster_group = c(1L, 2L, 2L, 1L, 3L, 3L, 1L, 1L, 2L, 1L)), row.names = c(NA,
10L), class = "data.frame")
So this shows me the names (I apologize these aren't the exact same names shown in the other example data) and their respective groups.
What I would love to do is plot something like this (ignore the "90's" and "80's", where it says A or B I'd like that to be group 1 or 2 respectively)
Where I would take each respective group, and then "average" their data to create a line for each group over time. Does that make sense? I know that ggplot can use a "grouping" variable, and I also know that multiple geom_lines can be on a single graph, but besides that I am totally lost. Help!