srearl / cslqualtrics

R-based tools to format Qualtrics observation data
MIT License
0 stars 0 forks source link

docs: behaviour plot using echarts4r #6

Open srearl opened 6 months ago

srearl commented 6 months ago
obs <- DBI::dbGetQuery(
  conn = csl_obs_db,
  statement = "
  SELECT
  response_id,
  question,
  response
  FROM
  observations
  WHERE
  survey_id = 'SV_6W59cgkw9TdB6BM'
  ;
  "
)

jack_ids <- obs[
obs$response == "Jack B." &
grepl("^q2_", obs$question, ignore.case = TRUE),
]$response_id

jack_data <- obs[obs$response_id %in% c(jack_ids), ]

jack_behaviours_sum <- jack_data |>
  dplyr::filter(grepl("^q4$", question, ignore.case = TRUE)) |>
  nrow()

student_behaviours_sum <- jack_behaviours_sum

devtools::load_all("~/localRepos/cslqualtrics/")

jack_data |>
  dplyr::filter(grepl("^q4$", question, ignore.case = TRUE)) |>
  dplyr::group_by(response) |>
  dplyr::summarise(
    n       = dplyr::n(),
    percent = round((n / student_behaviours_sum) * 100)
  ) |>
  dplyr::ungroup() |>
  dplyr::full_join(
    y  = cslqualtrics::behaviour_types,
    by = c("response" = "behaviour")
  ) |>
  dplyr::arrange(
    type,
    response
  ) |>
  echarts4r::e_charts(x = response) |>
  echarts4r::e_bar(
    serie   = percent,
    name    = "student behaviour",
    legend  = FALSE,
    colorBy = data
  ) |>
  echarts4r::e_tooltip(trigger = "axis") |>
  echarts4r::e_x_axis(axisLabel = list(interval = 0, rotate = 315)) |>
  echarts4r::e_title("Jack") |>
  echarts4r::e_grid(bottom = "40%") |>
  echarts4r::e_color(color = c(cslqualtrics::behaviour_types$color)) |>
  echarts4r::e_y_axis(max = 60)
srearl commented 6 months ago

...in shiny

    # student_observations_data |>
    #   dplyr::filter(grepl("^q4$", question, ignore.case = TRUE)) |>
    #   dplyr::group_by(response) |>
    #   dplyr::summarise(
    #     n       = dplyr::n(),
    #     percent = round((n / student_behaviours_sum) * 100)
    #   ) |>
    #   dplyr::ungroup() |>
    #   dplyr::full_join(
    #     y  = cslqualtrics::behaviour_types,
    #     by = c("response" = "behaviour")
    #   ) |>
    #   dplyr::arrange(
    #     type,
    #     response
    #   ) |>
    #   echarts4r::e_charts(x = response) |>
    #   echarts4r::e_bar(
    #     serie   = percent,
    #     name    = "student behaviour",
    #     legend  = FALSE,
    #     colorBy = data
    #   ) |>
    #   echarts4r::e_tooltip(trigger = "axis") |>
    #   echarts4r::e_x_axis(axisLabel = list(interval = 0, rotate = 315)) |>
    #   echarts4r::e_title(input$observation_students) |>
    #   echarts4r::e_grid(bottom = "40%") |>
    #   echarts4r::e_color(color = c(cslqualtrics::behaviour_types$color)) |>
    #   echarts4r::e_y_axis(max = 60)