Quantcast
Viewing all articles
Browse latest Browse all 206553

ggplot - Labeling each line at the end using an arrow

The question probably sounds confusing, so here are a couple of pictures to illustrate what I am trying to achieve.

Currently, I have this: Image may be NSFW.
Clik here to view.
Currently

What I want: Image may be NSFW.
Clik here to view.
Desire

I somewhat know about the directlabels package and how to avoid clipping. But I cannot find anything about adding arrows/lines that labels and points to each line. I have plots with many more lines that are clustered together, so the arrows would really help.

Here is my code if you want to reproduce this plot. Thanks.

library(ggplot2)


year <- 2008:2018

cvd <- rnorm(11, 15, 1)
alz <- rnorm(11, 10, 0.5)
ui <- rnorm(11, 9, .8)
stro <- rnorm(11, 6, 3)

df <- data.frame("Year" = as.factor(rep(year, 4)), "Number of Deaths" = c(cvd, alz, ui, stro), "Cause of Death" = c(
  rep("Cardiovascular Disease", 11),
  rep("Alzheimers Disease", 11),
  rep("Unidentified Cause of Death", 11),
  rep("Stroke", 11)
))

ggplot(data=df, aes(x=Year, y=Number.of.Deaths, group=Cause.of.Death, color = Cause.of.Death)) + geom_line() +
  theme(legend.position = "none")

Viewing all articles
Browse latest Browse all 206553

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>