Alessandra Carioli
unread,Nov 17, 2015, 11:43:39 AM11/17/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Dear All,
I am using geom segment to underline a change in a variable (sort of time=0 and time=1). I would like to have this distinction through 2 different colors in geom_point (starting point and end point) and have it appear in the legend, but I am at loss on how it can be done…
here is my code:
ggplot(dt,aes(O_TFR,TFR))+
geom_point(col="green")+
geom_segment(aes(x=O_TFR,y=TFR,xend=TFR_1.1,yend=TFR_1))+
geom_point(aes(TFR_1.1,TFR_1), col="red")
and the data:
dt <-structure(list(Country = structure(c(1L, 7L, 6L, 8L, 19L, 10L,
13L, 15L, 17L, 18L, 2L, 3L, 5L, 4L, 9L, 11L, 12L, 14L, 16L), .Label = c("Austria",
"Bulgaria", "Czech Rep.", "East Germany", "Estonia", "Finland",
"Flanders", "France", "Hungary", "Italy", "Latvia", "Lithuania",
"Norway", "Poland", "Portugal", "Slovenia", "Spain", "Sweden",
"West Germany"), class = "factor"), FFS_DFS = c(2, 2.01, 2.42,
2.27, 1.88, 2.07, 2.36, 2.1, 2.2, 2.42, 1.9, 2, 2.39, 1.88, 2.1,
2.1, 2.1, 2.2, 2.23), TFR = c(2.1, 2.16, 2.73, 2.49, 2.02, 2.17,
2.3, 2.16, 2.41, 2.62, 2.01, 2.21, 2.49, 1.97, 2.2, 2.25, 2.14,
2.33, 2.38), p0_1 = c(0.9, 0.905, 0.95, 0.952, 0.92, 0.966,
0.98, 0.957, 0.964, 0.96, 0.975, 0.98, 0.963, 0.98, 0.99, 0.988,
0.91, 0.93, 0.9), TFR_1 = c(2.24, 2.39, 2.87, 2.61, 2.2,
2.25, 2.4, 2.26, 2.5, 2.73, 2.06, 2.23, 2.59, 2, 2.22, 2.28,
2.23, 2.49, 2.37), O_TFR = c(1.75, NA, 1.82, NA, NA, NA, 2.03,
1.72, NA, 2.18, 1.443, 1.84, 1.7, NA, 1.95, NA, 1.67, NA, 1.72
), O_p0_1 = c(0.879, NA, 0.75, NA, NA, NA, 0.878, 0.883, NA,
0.926, 0.798, 0.837, 0.825, NA, 0.867, NA, 0.848, NA, 0.838),
TFR_1.1 = c(1.99, NA, 2.43, NA, NA, NA, 2.31, 1.94, NA, 2.35,
1.79, 2.17, 1.94, NA, 2.25, NA, 1.97, NA, 2.05)), .Names = c("Country",
"FFS_DFS", "TFR", "p0_1", "TFR_1", "O_TFR", "O_p0_1", "TFR_1.1"
), class = “data.frame", row.names = c(NA, -19L))