Skip to content

Instantly share code, notes, and snippets.

@emitanaka

emitanaka/graph.R

Created Jan 30, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@emitanaka emitanaka commented Jan 30, 2019

rplot

@emitanaka

This comment has been minimized.

Copy link
Owner Author

@emitanaka emitanaka commented Jan 30, 2019

Original: wechatimg83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.