library(APCtools)
# define categorizations for the main trip distance
dist_cat_breaks <- c(1,500,1000,2000,6000,100000)
dist_cat_labels <- c("< 500 km","500 - 1,000 km", "1,000 - 2,000 km",
"2,000 - 6,000 km", "> 6,000 km")
age_groups <- list(c(80,89),c(70,79),c(60,69),c(50,59),c(40,49),c(30,39),c(20,29))
period_groups <- list(c(1970,1979),c(1980,1989),c(1990,1999),c(2000,2009),c(2010,2019))
cohort_groups <- list(c(1980,1989),c(1970,1979),c(1960,1969),c(1950,1959),c(1940,1949),
c(1930,1939),c(1920,1929))
plot_densityMatrix(dat = travel,
y_var = "mainTrip_distance",
age_groups = age_groups,
period_groups = period_groups,
log_scale = TRUE)
# \donttest{
# highlight two cohorts
plot_densityMatrix(dat = travel,
y_var = "mainTrip_distance",
age_groups = age_groups,
period_groups = period_groups,
highlight_diagonals = list(8, 10),
log_scale = TRUE)
# also mark different distance categories
plot_densityMatrix(dat = travel,
y_var = "mainTrip_distance",
age_groups = age_groups,
period_groups = period_groups,
log_scale = TRUE,
y_var_cat_breaks = dist_cat_breaks,
y_var_cat_labels = dist_cat_labels,
highlight_diagonals = list(8, 10),
legend_title = "Distance category")
# flexibly assign the APC dimensions to the x-axis and y-axis
plot_densityMatrix(dat = travel,
y_var = "mainTrip_distance",
dimensions = c("period","cohort"),
period_groups = period_groups,
cohort_groups = cohort_groups,
log_scale = TRUE,
y_var_cat_breaks = dist_cat_breaks,
y_var_cat_labels = dist_cat_labels,
legend_title = "Distance category")
# use boxplots instead of densities
plot_densityMatrix(dat = travel,
y_var = "mainTrip_distance",
plot_type = "boxplot",
age_groups = age_groups,
period_groups = period_groups,
log_scale = TRUE,
highlight_diagonals = list(8, 10))
# plot categorical variables instead of metric ones
plot_densityMatrix(dat = travel,
y_var = "household_size",
age_groups = age_groups,
period_groups = period_groups,
highlight_diagonals = list(8, 10))
# }
Run the code above in your browser using DataLab