Entering edit mode
3.2 years ago
waqasnayab
▴
250
Hi,
I am in the process of plotting a dumbbell with ggplot2 and (ggalt). Attaching thr dumy data and R code. I am unable to add any of the third time point, but can add 1 and 2, 2 and 3 and 3 and 1.
The plot should be sorted on the basis of gaoutcome_days which is done, but I tried to add the third time point, that is, I mean to say the seocnd time point right now (gasample2_weeks), but no luck. The code I developed is:
library(readxl)
library(dplyr)
library(ggplot2)
library(ggalt)
library(tidyr)
# load data
ges_age <- read_excel("dummy_wuk.xlsx", sheet = 1)
View(ges_age)
# create dumbbell plot
ggplot(ges_age,
aes(y = reorder(whowid, gaoutcome_weeks), x =gasample1_weeks, xend = gaoutcome_weeks)) +
geom_dumbbell(size = 1.2,
size_x = 3,
size_xend = 3,
colour = "yellow",
colour_x = "blue",
colour_xend = "red") +
theme_minimal() +
labs(title = "GA",
subtitle = "per trimester",
x = "weeks",
y = "")
The data is:
whowid gasample1_weeks gasample2_weeks gaoutcome_weeks
36790 19 24 40
36821 19 32 39
36912 19 32 38
36916 19 26 37
36941 19 24 39
36994 18 28 44
37043 19 24 37
37046 16 24 38
37063 19 32 40
37068 19 25 40
37117 19 24 42
37120 16 24 39
37122 16 32 37
37168 18 28 38
I am still reading this: [https://rud.is/b/2016/04/17/ggplot2-exercising-with-ggalt-dumbbells/]. Any help or hint is highly appreciated.
Waqas.