I have the following dataframe:
test = structure(list(Student = c("Ana", "Brenda", "Max", "Ana", "Brenda",
"Max", "Ana", "Brenda", "Max"), Month = structure(c(1L, 1L, 1L,
2L, 2L, 2L, 3L, 3L, 3L), .Label = c("January", "February", "March"
), class = "factor"), Grade = c(7L, 6L, 7L, 8L, 6L, 7L, 5L, 10L,
10L), Change = c("February", "February", "February", "February",
"February", "February", "February", "February", "February")), row.names = c(NA,
-9L), class = "data.frame")
I plotted the grades of each student throughout the months, and wanted to know if there is a simple way to accentuate a specific part of each plotted line that would correspond to the period of time which showed the greatest shift in their grades (this info is already present in the dataset: column "Change". In this case, for all students it would be from February to March).
Trying to use a similar logic as presented here, to change the color a specific part of the line I attempted to change the linetype and/or size of the line (since I already used the color to group and display each student) in order to highlight that particular portion of the line. However, it doesn't seem to be as straightforward.
My attempts were the following:
ggplot(test, aes(x = Month, y = Grade, color = Student, group = Student)) +
+ geom_point() + geom_line(data = test, aes(linetype = (ifelse(Month == Change, "solid", "dashed"))))
Which yielded the error:
Error: geom_path: If you are using dotted or dashed lines, colour, size and linetype must be constant over the line
And
ggplot(test, aes(x = Month, y = Grade, color = Student, group = Student)) +
geom_point() + geom_line(data = test, aes(size = (ifelse(Month == Change, 1, 0.8))))
Which kinda does what I'm looking for, but looks horrible, and doesn't really seem like its using the size of the line that I'm trying to specify:
How do I fix it? Thanks in advance! n_n




