2 separate independent graph in the same graph
I have data like this:
mydata( var0 = 4,4,4,4.5,4.5,4.6,4.8,5.5,5.7,7,7.5,7.6,8,8.5,8.6,9,9,9.5,9.6,10 var1 = 10,9.6,9.5,9.3,8,8.5,8.3,7.5,7,7,6.8,6.7,6.3,6,5.5,5.3,4.8,4.5,4.3,4 con0 = 0,5,10,15,50,80,100,150,180,200,220,250,300,350,400,450,480,500,550,600 con1= 600,580,550,530,480,460,450,350,330,300,200,170,165,120,75,65,25,15,10,0 )
I want con0 and con1 on the y-axis and its corresponding var0 and var1 values ββon the x-axis. is there any way to plot 2 separate independent graph in the same graph. I tried to do it with the following code using only con0, but the problem is I will switch to form change. any suggestions?
ggplot(mydata, aes(y = con0)) +
geom_line(aes(x = var0, colour = "ascent")) +
geom_line(aes(x = var1, colour = "descent"))
+3
source to share
1 answer
Is this what you mean?
library(ggplot)
df <- data.frame(
var0 = c(4,4,4,4.5,4.5,4.6,4.8,5.5,5.7,7,7.5,7.6,8,8.5,8.6,9,9,9.5,9.6, 10),
var1 = c(10,9.6,9.5,9.3,8,8.5,8.3,7.5,7,7,6.8,6.7,6.3,6,5.5,5.3,4.8,4.5,4.3,4),
con0 = c(0,5,10,15,50,80,100,150,180,200,220,250,300,350,400,450,480,500,550,600),
con1= c(600,580,550,530,480,460,450,350,330,300,200,170,165,120,75,65,25,15,10,0)
)
ggplot(df) +
geom_line(aes(x = var0, y = con0), color = 'red') +
geom_line(aes(x = var1, y = con1), color = 'blue')
+3
source to share