JannisCodes / PsyCorona-WebApp

Interactive Shiny Web App to visualize the survey data of the PsyCorona project @ https://psycorona.org/
Other
3 stars 3 forks source link

Add developmental visualisation #9

Open JannisCodes opened 4 years ago

JannisCodes commented 4 years ago

Inspiration from previous project:

FeedbackDaily <- AOTM_Daily %>%
  filter(!is.na(ended)) %>%
  select(ended, exWB, energy, afraid, angry, Autonomy, Competence, RelatednessOther, RelatednessSelf, RelatednessNoInteraction, AttitudesDutch, Interaction, StudentGoal01, StudentGoal02, StudentGoal03, StudentGoal04, StudentGoal05, StudentGoal06, StudentGoal07, StudentGoal08, StudentGoal09, StudentGoal10)
FeedbackDaily$dateTime <- as.POSIXct(FeedbackDaily$ended)
FeedbackDaily$RelatednessNoInteractionRev <- FeedbackDaily$RelatednessNoInteraction*-1+100
FeedbackDaily$Relatedness <- rowMeans(FeedbackDaily %>% select(RelatednessOther, RelatednessSelf, RelatednessNoInteractionRev), na.rm = T)

highcharter::highchart(type = "stock") %>% 
  hc_chart(type = "line", zoomType = "x") %>% 
  #hc_title(text = "Your Well-Being") %>% 
  hc_xAxis(type = "datetime") %>% 
  hc_yAxis(title = list(text = "Well-Being"),
           min = -100,
           max = 100,
           showLastLabel = T,
           showFirstLabel = T,
           plotLines = list(
           list(label = list(text = "Neutral"),
                color = "#'FF0000",
                width = 2,
                value = 0),
           list(label = list(text = "Negative"),
                color = "#'FF0000",
                width = 2,
                value = -100),
           list(label = list(text = "Positive"),
                color = "#'FF0000",
                width = 2,
                value = 100))) %>% 
  hc_plotOptions(line = list(
    dataLabels = list(enabled = F),
    enableMouseTracking = TRUE)
    ) %>% 
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(datetime_to_timestamp(dateTime), exWB), 
                name="Well-Being", 
                marker = list(enabled = TRUE, radius=3))%>%
  hc_rangeSelector( 
    verticalAlign = "top",
    buttons = list(
    list(type = 'all', text = 'All'),
    list(type = 'day', count = 14, text = '14d'),
    list(type = 'day', count = 7, text = '7d'),
    list(type = 'hour', count = 48, text = '48h'),
    list(type = 'hour', count = 24, text = '24h')
  ))

randStGoal <- sample(c("TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE"))

highcharter::highchart(type = "stock") %>% 
  hc_chart(type = "line", zoomType = "x") %>% 
  #hc_title(text = "Your Mood") %>% 
  hc_xAxis(type = "datetime") %>% 
  hc_yAxis(title = list(text = "Mood"),
           min = 0,
           max = 100,
           showLastLabel = T,
           showFirstLabel = T,
           opposite = TRUE,
           plotLines = list(
           list(label = list(text = "Not important"),
                color = "#'FF0000",
                width = 2,
                value = 0),
           list(label = list(text = "Very important"),
                color = "#'FF0000",
                width = 2,
                value = 100))) %>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal01), 
                name=c("Social Support Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[1]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal02), 
                name=c("Romantic Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[2]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal03), 
                name=c("Academic Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[3]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal04), 
                name=c("Career Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[4]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal05), 
                name=c("Financial Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[5]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal06), 
                name=c("Health Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[6]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal07), 
                name=c("Leisure Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[7]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal08), 
                name=c("Personal Improvement Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[8]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal09), 
                name=c("Helping Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[9]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_add_series(FeedbackDaily, "spline", 
                hcaes(x = datetime_to_timestamp(dateTime), y = StudentGoal10), 
                name=c("Spiritual Goal"),
                showInNavigator = TRUE,
                visible = as.logical(randStGoal[10]),
                marker = list(enabled = TRUE, radius=3, symbol = "circle"))%>%
  hc_colors(brewer.pal(10, "Dark2"))%>%
  hc_legend(enabled = TRUE)%>%
  hc_plotOptions(
    line = list(
      dataLabels = list(enabled = F),
      enableMouseTracking = TRUE, 
      showInNavigator = TRUE)
    )%>%
  hc_rangeSelector( 
    verticalAlign = "top",
    buttons = list(
    list(type = 'all', text = 'All'),
    list(type = 'day', count = 14, text = '14d'),
    list(type = 'day', count = 7, text = '7d'),
    list(type = 'hour', count = 48, text = '48h'),
    list(type = 'hour', count = 24, text = '24h')
  ))
maxAgostini commented 4 years ago

It would be cool to have a development per month (data for february, ...) as well as the development of the waves (w1 until w11)