Skip to content
Snippets Groups Projects
Commit a9a63634 authored by Ben Anderson's avatar Ben Anderson
Browse files

added ggplot histograms of start times & episode durations

parent 6f1515ba
Branches
No related tags found
No related merge requests found
...@@ -68,6 +68,7 @@ reqLibsLocal <- c("foreign", # loading SPSS/STATA ...@@ -68,6 +68,7 @@ reqLibsLocal <- c("foreign", # loading SPSS/STATA
"data.table", # fast data manipulation "data.table", # fast data manipulation
"dplyr", # data manipulation "dplyr", # data manipulation
"dtplyr", # data table & dplyr code "dtplyr", # data table & dplyr code
"ggplot2", # slick graphs
"stargazer", # for pretty tables "stargazer", # for pretty tables
"knitr" # for kable "knitr" # for kable
) )
...@@ -662,14 +663,6 @@ Now the HH:MM version: ...@@ -662,14 +663,6 @@ Now the HH:MM version:
r_epStartM), r_epStartM),
format = "%H:%M") format = "%H:%M")
] ]
print("# Check distributions of episode starts (all surveys pooled)")
t <- mtusUKEpsDT[,
.(
N = length(epnum)
),
by = r_epStartTime
]
plot(t)
# create episode end # create episode end
mtusUKEpsDT$r_epEndTime <- mtusUKEpsDT$r_epStartTime + (mtusUKEpsDT$end*60) mtusUKEpsDT$r_epEndTime <- mtusUKEpsDT$r_epStartTime + (mtusUKEpsDT$end*60)
...@@ -681,6 +674,27 @@ Now the HH:MM version: ...@@ -681,6 +674,27 @@ Now the HH:MM version:
summary(mtusUKEpsDT$r_epEndTime) summary(mtusUKEpsDT$r_epEndTime)
``` ```
```{r plotStartTimes, fig.cap = "Check distributions of episode starts by survey"}
ggplot(mtusUKEpsDT) +
geom_histogram(aes(x = r_epStartTime)) +
scale_x_datetime(date_labels = "%H:%M", date_breaks = "2 hours") +
facet_grid(survey ~ .) +
labs(
caption = "MTUS UK samples"
)
```
```{r plotDurations, fig.cap = "Check distributions of episode durations by survey"}
mtusUKEpsDT <- mtusUKEpsDT[, epDurationMins := (r_epEndTime - r_epStartTime)/60]
ggplot(mtusUKEpsDT) +
geom_histogram(aes(x = epDurationMins)) +
facet_grid(survey ~ .) +
labs(x = "Episode duration (minutes)", caption = "MTUS UK samples")
```
## Create half hours ## Create half hours
Create and check the distribution of half hours. This uses the epStartTime variable to make sure it is set for all cases, even those which still have no date: Create and check the distribution of half hours. This uses the epStartTime variable to make sure it is set for all cases, even those which still have no date:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment