Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Last active April 10, 2022 13:23
Show Gist options
  • Save juanchiem/9fe7b03642b0048ac1488e13bd848f42 to your computer and use it in GitHub Desktop.
Save juanchiem/9fe7b03642b0048ac1488e13bd848f42 to your computer and use it in GitHub Desktop.
dat <- data.frame(
stringsAsFactors = FALSE,
trt = c(2,2,2,2,2,2,2,10,10,10,
10,10,10,10,2,2,2,2,2,2,2,10,10,10,10,10,
10,10,2,2,2,2,2,2,2,10,10,10,10,10,10,10),
par = c("2_1","2_1","2_1","2_1",
"2_1","2_1","2_1","10_1","10_1","10_1","10_1","10_1",
"10_1","10_1","2_2","2_2","2_2","2_2","2_2","2_2",
"2_2","10_2","10_2","10_2","10_2","10_2","10_2",
"10_2","2_3","2_3","2_3","2_3","2_3","2_3","2_3",
"10_3","10_3","10_3","10_3","10_3","10_3","10_3"),
bk = c(1,1,1,1,1,1,1,1,1,1,1,
1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,
3,3,3,3,3,3,3,3,3,3,3,3),
tt = c(15,58,95,146,165,180,248,
15,58,95,146,165,180,248,15,58,95,146,165,
180,248,15,58,95,146,165,180,248,15,58,95,146,
165,180,248,15,58,95,146,165,180,248),
inc = c(1,10,20,19,16,19,19,4,
39,55,57,49,54,54,1,13,15,51,18,15,18,1,25,
39,44,40,43,43,1,5,13,15,13,14,15,4,40,47,
53,10,47,45)
)
dat %>%
ggplot()+
aes(x=tt, y=inc)+
geom_line()+
geom_point()+
facet_wrap("par")
dat %>%
mutate(inc = case_when(
par == "10_3" & tt == "165" ~ NA_real_,
par == "2_2" & tt == "146" ~ NA_real_,
TRUE ~ inc)) %>%
group_by(par) %>%
mutate(inc = zoo::na.approx(inc, na.rm=FALSE)) -> dat2
dat2 %>%
ggplot()+
aes(x=tt, y=inc)+
geom_line()+
geom_point()+
facet_wrap("par")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment