I have an issue on how to display segment with geom_segment in ggplot graph. I have individuals which are measurements on height and body mass related to Age, and after making a plot I would like to link those two variables (height and body mass) to see clearly one individual with adding its label (here there are identify by number, putted in character).
So its look like this :
ID | height | Bodymass | Age |
---|---|---|---|
2154 | 1,80 | 80 | 42 |
And I made this plot :
And I would like something like this :
I have tried with geom_segment and geom line but still some errors which I don't understand Here what I have tried before :
ggplot(BM_height, aes(x=Age)) +
geom_smooth(aes(y=height), method="loess", col="blue") +
geom_point(aes(y=height),col="blue")+
geom_smooth(aes(y=BodyMass * scaleFactor), method="loess", col="red") +
geom_point(aes(y=BodyMass/10),col="red")+
#geom_segment(aes(x = Age, y = height, xend = Age, yend = BodyMass))+
scale_y_continuous(name="height (cm)", sec.axis=sec_axis(~./scaleFactor, name="Body mass (g)")) +
theme(
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red")
)
)
#geom_text(BM_height, mapping=aes(label=ID_new), stat="identity")