library( shinyLikert )
  load( "cattell_data.rda")
 # display the fator overview
 fluidPage(
   renderFactorOverview( cattell_data )
 )

 # add question as column_factor. This way, questions can be selected
 # through a dropdown input
 cattell_data$column_factors = cbind( 
   cattell_data$column_factors,
   question = names(cattell_data$likert_data)
  )

 # only allow observations with frequent ages
 age = cattell_data$row_factors$age
 frequent_ages = names(summary(age))[1:3]
 cattell_data$likert_data  = cattell_data$likert_data[age%in%frequent_ages,]
 cattell_data$row_factors  = cattell_data$row_factors[age%in%frequent_ages,]
 cattell_data$row_factors$age = factor( cattell_data$row_factors$age )

 #only allow observations with frequent countrys
 country = cattell_data$row_factors$country
 frequent_countries = names(summary(country))[1:3]
 cattell_data$likert_data  = cattell_data$likert_data[country%in%frequent_countries,]
 cattell_data$row_factors  = cattell_data$row_factors[country%in%frequent_countries,]
 cattell_data$row_factors$country = factor( cattell_data$row_factors$country )

 # remove some entries to speed up the server tasks. Note, that this
 # dataset had 49159 participants
 cattell_data$likert_data  = cattell_data$likert_data[1:2000,]
 cattell_data$row_factors  = cattell_data$row_factors[1:2000,]

 # show summary for the shortened data set
 summary( cattell_data )

 rendered2 = renderShinyLikert(
   cattell_data , 
   dropdown = c( "question_type", "question" ),
   split = c( "source", "gender" ),
   response_levels = c( 
     #"missed",                      # do not plot the missings
                                     # this can be avoided by replacing
                                     # missed with NAs in likert_data
     "strongly disagree", 
     "disagree", 
     "neither agree not disagree", 
     "agree", 
     "strongly agree" ),
   as.percent = TRUE
 )
 rendered2$selector
 rendered2$plot 
 # replace missing answers with NAs
 i = 1
 for( question in cattell_data$likert_data ){
   question[question == "missed"] = NA
   cattell_data$likert_data[,i] = factor( question )
   i = i + 1
 }

 # Call renderShinyLikert and plot the result
 plot(
   renderShinyLikert(
     cattell_data,
     dropdown = c( "question_type" ),
     group = "gender",
     as.percent = TRUE,
     height = c(750,1500)
   )
 )

  plot(
   renderShinyLikert(
     cattell_data,
     dropdown = c( "question_type" ),
     group = "gender",
     grouping = "HH",
     as.percent = TRUE,
     height = c(750,1500)
   )
 )


GregorDeCillia/shinyLikert documentation built on May 6, 2019, 6:36 p.m.