I'm trying to plot 3 different cross sections that are going to be coloured by a certain factor. This all works fine, however for some reason the geom_line()
function doesn't manage to interrupt the plotted line by the factors. Here is my code (I have removed all code explanations) so far:
library(ggplot2)
qpbase_soll <- ggplot(qps_soll, aes(X, Ysoll))
qpbase_soll <- qpbase_soll + geom_line(aes(color = Katsoll), size = 1) + facet_grid(Profil ~ .) + labs(x = "Horizontaldistanz [m]") + labs(y = "Höhe über Meer [m]")
farben_qp2 <- c("red", "darkgreen", "orange", "lightgreen")
qpbase_soll <- qpbase_soll + scale_colour_manual(values=farben_qp2)
qpbase_soll <- qpbase_soll + coord_fixed(ratio=2/1)
qpbase_soll <- qpbase_soll + scale_x_continuous(breaks=c(0,5,10,15,20,25,30)) + scale_y_continuous(breaks=c(630:637))
library(grid)
qpbase_soll <- qpbase_soll + theme(panel.margin = unit(1, "lines"))
qpbase_soll <- qpbase_soll + labs(colour= "Oberfläche")
qpbase_soll <- qpbase_soll + ggtitle("Querprofile SOLL-Zustand") + theme(plot.title= element_text(face="bold"))
kommentar_y4 <- data.frame(X = 23, Ysoll = 635, lab = "Alle Y-Achsen zweifach überhöht", Profil = factor("QP2"))
qpbase_soll <- qpbase_soll + geom_text(data = kommentar_y4, label = "Alle Y-Achsen zweifach überhöht", size = 3.0, color = "darkgrey")
qpbase_soll
My data.frame()
contains X and Y values, as well as a category for all these locations according to the colours they should receive. So the line should actually be interrupted for all categories. The data sheet has the following entries:
Profil X Ysoll Katsoll
QP1 0.0 636.4 Terrain
QP1 0.5 636.3 Terrain
QP1 1.6 638.5 Feldweg
QP1 1.8 638.5 Feldweg
QP1 2.0 639.1 Terrain
...
What am I doing wrong?