Git Product home page Git Product logo

quick-plotting-summarizing's Introduction

Functions to Summarise and Plot Survey Data

These function were made to aid in quickly tabulating survey data percentages and cross-tab summaries for surveys. The functions were also made to be used with population weights.

These summary functions can be combined and chained with the plotting variables to quickly create and reiterate good-looking plots for quick exploration and export.

These functions create bar charts of various kinds

  • Ordered by magnitude or unordered
  • horizontal or vertical
  • faceted

Number data annotations are automatically added to charts and aligned without having to manually fiddle with limits.

Basic Bar Plot

df  %>% PctCalcOne( 'Q1', 'weight_r') %>% 
  plot_bar(xvar = Q1 , yvar = pct, 
           title="How many times has Los Angeles hosted the Summer Olympics?",
           subtitle= paste("n: ", NROW(df %>% filter(!is.na(Q1)))),
           x = "", y ="Percent") 

Basic Bar Plot Horizontal

df %>% PctCalcOne('Q_Age_f', 'weight_r') %>% 
  plot_bar2(xvar = Q_Age_f , yvar = pct, relsizex = 1, relsizey = 1, 
            subtitle= paste("n: ", NROW(df %>% filter(!is.na(Q_Age_f)))),
            title = "Age - Reweighted Sample",
            x = "", y ="Percent") + 
            scale_x_discrete(labels =  c("18 - 34", "35 -54", "65 +")) 

Bar Plot With Order Horizontal

df %>% PctCalcOne('Eth', 'weight_r') %>% 
  plot_bar_reorder2(xvar = Eth, yvar = pct, relsizex = 1, relsizey = 1, 
                    title = "Ethnicity - Reweighted Sample",
                    subtitle= paste("n: ", NROW(df %>% filter(!is.na(Eth)))),
                    x = "", y ="Percent")

Cross-Tabbed Summary / Faceted Bar Plot

df %>% PctCalcTwo('Q_LaCountyReside', 'Q4', 'weight_r') %>% 
  plot_bar_fill_dodge(xvar = as.factor( Q4 ) , yvar = pct, fillvar = as.factor(Q_LaCountyReside),  
                      title="How supportive or opposed are you of Los Angeles hosting the Summer Olympic Games in 2028?",
                      subtitle= paste("n: ", NROW(df %>% filter(!is.na(Q4) ))),
                      x = "", y ="Percent") + scale_fill_discrete(labels = label_la )  +                        
                      scale_x_discrete(labels = label_oppose_support )

Cross-Tabbed Summary / Faceted Bar Plot Flipped

df %>% PctCalcTwo('Q_LaCountyReside', 'Q_Budget', 'weight_r') %>% 
  plot_bar_fill_dodge2(xvar = as.factor( Q_Budget ) , yvar = pct, fillvar = as.factor(Q_LaCountyReside),
    title="What is the official budget for the 2028 Summer Olympics?", flip = TRUE,
    subtitle= paste("n: ", NROW(df %>% filter(!is.na(Q_Budget) ))),
    x = "", y ="Percent")  + 
    scale_x_discrete(labels = pos_Q_Budget ) + 
    scale_fill_discrete(labels = pos_la ) 

Cross-Tabbed Summary / Faceted Bar Plot Re-Ordered

df %>% filter( ) %>% PctCalcTwo('Q_LaCountyReside', 'Q_Num_Host', 'weight_r') %>% 
  plot_bar_fill_dodgeReorder(xvar = Q_Num_Host , yvar = pct, fillvar =  as.factor(Q_LaCountyReside),
    title="How many times has Los Angeles Hosted the Summer Olympics?",
    subtitle= paste("n: ", NROW(df %>% filter(!is.na(Q_CityWithdraw)))),
    x = "", y ="Percent") + 
    scale_fill_discrete( labels = pos_la)

quick-plotting-summarizing's People

Contributors

azadag avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.