Home > Software design >  Slope Chart - ggplot2
Slope Chart - ggplot2

Time:01-01

I am testing some templates of ggplot2, and I am interesting to the slope chart, available from here:

enter image description here

If I add only another item in the same column everything is fine and the connecting line appears.

Is there a way to have the lines also in this situation? I have tried on a lot of ways, removing the lines containing NA values without success, therefore I do not know how to fix this problem, if ... it is possible to be fixed.

Thank you in advance for every eventual reply!

CodePudding user response:

May I suggest a much easier way, with the {ggh4x} package, which has a base R type = "b" like geom. You can remove the points, and plot text instead.

You'll get your result in three lines of code :)

library(tidyverse)
library(ggh4x)

source_df <- read.csv("https://raw.githubusercontent.com/jkeirstead/r-slopegraph/master/cancer_survival_rates.csv")
source_df <- filter(source_df, group == "Thyroid")

ggplot(source_df, aes(year, value))  
## set shape to NA                
  geom_pointpath(aes(group = group, mult = 1), shape = NA)   
  geom_text(aes(label = value))

Created on 2021-12-30 by the reprex package (v2.0.1)

  • Related