Reputation: 414
I need to create an upward and downward profile of temperature w.r.t height. My problem is I am not able to separate the two parts and hence the result is not what I want. below is the imaginary data:
height,temp
0,50.5
200,25.2
400,11.6
600,4.9
800,2.2
1000,1.4
800,1.3
600,2.6
400,10.1
200,16.4
0,20.8
When I plot height vs temp , I want a profile until 0-1000(upward) and a second profile 1000-0(downward)in the same plot using ggplot2. How can I separate it?
Upvotes: 0
Views: 87
Reputation: 5932
If I understand correctly the question, the simplest way would be to add a supplementary column to specify which points correspond to the "up" and which to the "down" profile. SOmething like:
df <- mutate(df, trend = c(rep("up",6), rep("down",5)))
p <- ggplot(df, aes(x = height, y = temp, color = trend)) +
geom_line()
p
If you want to "connect" the two lines at 1000, you'd just have to add a "fake" replicated point at height = 1000 and assign it to "down".
Upvotes: 2