Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created February 21, 2022 12:16
Show Gist options
  • Select an option

  • Save MJacobs1985/34f62c65e8b25b47b06a205b86dfbbe4 to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/34f62c65e8b25b47b06a205b86dfbbe4 to your computer and use it in GitHub Desktop.
## Add run identifier for days
dfcurve<-df%>%
filter(!is.na(curve_day))
dfcurve<-dfcurve[, colSums(is.na(dfcurve)) != nrow(dfcurve)]
dfnocurve<-df%>%filter(is.na(curve_day) & !is.na(feed_provided_cum))
dfnocurve%>%
arrange(lcn_id, date_interval)%>%
group_by(lcn_id)%>%
mutate(curve_day = ifelse(min(feed_provided_cum), 1, 0))%>%
dplyr::select(lcn_id,feed_provided,feed_provided_cum,curve_day)%>%print(n=200)
dfnew<-df%>%
filter(!is.na(curve_day))%>%
group_by(lcn_id) %>%
mutate(flagtag = ifelse(curve_day==1,1,0),
newField = 1 + cumsum(flagtag))%>%
arrange(lcn_id, date_interval)
dfnew$lcn_id<-as.factor(dfnew$lcn_id)
dfnew$newField<-as.factor(dfnew$newField)
df%>%
filter(lcn_id%in%(901:906))%>%
ggplot(., aes(x=curve_day,
y=feed_provided_cum,
group=lcn_id))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id, ncol=3)
dfnew%>%
filter(lcn_id%in%(901:906))%>%
ggplot(., aes(x=curve_day,
y=feed_provided_cum,
colour=as.factor(newField)))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id, ncol=3)
dfnew%>%
filter(lcn_id%in%(901:906) & feed_provided>0)%>%
ggplot(., aes(x=curve_day,
y=feed_provided,
colour=as.factor(newField)))+
geom_point()+
theme_bw()+
facet_wrap(~lcn_id, ncol=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment