this is the first question I post here, so please excuse if I don't provide all information right away.
I'm trying to build a line graph with two lines:
y1 <- c(1000,1500,1000,1500,2000,3000,4000)
y2 <- c(1100,1400,900,1500,2000,2500,3500)
x <- c(49,50,51,1,2,49,50)
df <- data.frame(y1,y2,x)
Imagine x being calendar weeks, I skipped the weeks between 3 and 48 of the second year. Now I want to build a line graph, which display the x-axis values (time series) in this order.
First I tried a really simple approach:
p <- ggplot()
p <- p + geom_line(data=df,aes(x=x,y=y1))
p <- p + geom_line(data=df,aes(x=x,y=y2), color = "red")
p
Problem: R sorts the x values and also sums up same week numbers.
I then tried to change the x values to make them unique, e.g. 49/19,50/19, but R still changes the order. Same happens if I use geom_path instead of geom_line.
I then tried to change x to a factor and use x_scale_discrete, but I couldn't figure out, how to do it, either the lines or the x labels were always missing.
I hope you can give me some kind of advice.
Many thanks,
Andre

