r – Remove vertical lines in my spaghetti plot (ggplot2)
I created a spaghetti plot using ggplot2 R in R Studio, displaying symptom courses from t1 (pre) to t2 (post) and using different load scores as lines (load scores can reach from 0 to 4).
My current code is:
spaghettiplot_PTSD <- ggplot(data = data_KIDNET, aes(x = MZP_Factor, y = CAPS50, group = loadscore_factor)) +
geom_line(aes(color=loadscore_factor)) +
scale_color_manual(values=c("#ee7bae","#ce0075", "#951b81", "#59358c", "#00305d")) +
labs(color = "load score", x = "diagnostics measurement point", y="PTSD symptom score") +
theme_bw() +
scale_x_discrete(labels=c("pre", "post"), expand = c(0.05, 0.05))
spaghettiplot_PTSD
I added scale_x_discrete(), expand = c(0.05, 0.05)), because I like it when there is a little space inside the plot between the t1 and the y axis as well as on the other side to have some space between t2 to the end of the plot.
My problem is, that when I add this, R draws 2 more vertical lines, one on t1 and one on t2, which I do not want.

My question is: How can I add these spaces on the left and right of my plots inside my graph but at the same time get rid of these two vertical lines?
I found this q&a which is very similar (Remove vertical lines in ggplot) and tried to solve my problem by replacing group = loadscore_factor with group = paste(loadscore_factor, ID, sep =".") but this did not help.
I am happy for any advices! Thank you in advance!
Please tell me if you need more information – as this iy my first question in stackoverflow and as I am still very new to R there might be something missing.
M
Read more here: Source link
