Skip to content

Instantly share code, notes, and snippets.

@emitanaka
Created January 30, 2019 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emitanaka/6fcded36289def2c4537dedd51ac43de to your computer and use it in GitHub Desktop.
Save emitanaka/6fcded36289def2c4537dedd51ac43de to your computer and use it in GitHub Desktop.
child geom point plot for CY
library(tidyverse)
library(ggrepel)
dat <- tibble::tribble(
~Visits, ~FEV, ~No, ~Group, ~Line, ~Child,
"0", 78, NA, "Smokers", 1, NA,
"1", 76, 2682, "Smokers", 1, 1,
"2", 74, 2335, "Smokers", 1, 2,
"3", 73, 2959, "Smokers", 1, NA,
"2", 79, 208, "Outliers", "O1", 1,
"3", 78, 152, "Outliers", "O2", 2,
"0", 79, NA, "Outliers", 2, NA,
"1", 82, 2682, "Outliers", 2, NA,
"2", 82, 2335, "Outliers", 2, NA,
"3", 83, 2959, "Outliers", 2, NA
) %>% mutate(Visits=factor(Visits))
levels(dat$Visits) <- c("BL", "AV1", "AV2", "AV3")
all_dots <- dat %>% filter(Visits!="BL")
dots_labelinside <- all_dots %>% filter(Line %in% 1:2)
dots_labeloutside <- all_dots %>% filter(!(Line %in% 1:2))
ggplot(dat, aes(Visits, FEV)) +
geom_line(aes(group=Line)) +
geom_line(data=subset(dat, !is.na(Child)), aes(group=Child)) +
geom_point(data=all_dots, pch=21, aes(size=I(No/400 + 2), fill=Group)) +
geom_text(data=dots_labelinside, aes(label=No), size=2, color="white") +
geom_text_repel(data=dots_labeloutside, aes(label=No), size=2, color="black", nudge_x = 0.05) +
theme(legend.position = "bottom") +
ylim(70, 90)
@emitanaka
Copy link
Author

rplot

@emitanaka
Copy link
Author

Original: wechatimg83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment