我肯定有n多种方法可以实现,至少下面这一种也可以:
- library(ggplot2)
- my_data <- data.frame(country = LETTERS[1:10],
- rate_2000 = sample(5:20, 10),
- rate_2015 = sample(15:30, 10))
- ggplot(my_data, aes(x = country)) +
- geom_segment(aes(y = rate_2000, xend = country, yend = rate_2015),
- size = 1.5, color = "lightgray")+
- geom_point(aes(y = rate_2000, color = "rate_2000"), size = 5) +
- geom_point(aes(y = rate_2015, color = "rate_2015"), size = 5) +
- coord_flip() +
- labs(x = NULL, y = NULL, color = NULL) +
- theme_bw() +
- theme(legend.position = "top") +
- scale_color_manual(values = c("blue", "lightblue"))
复制代码