Ggplot2 for Epi Studies

Total Page:16

File Type:pdf, Size:1020Kb

Ggplot2 for Epi Studies ggplot2 for Epi Studies Leah McGrath, PhD November 13, 2017 Introduction · Know your data: data exploration is an important part of research · Data visualization is an excellent way to explore data · ggplot2 is an elegant R library that makes it easy to create compelling graphs · plots can be iteratively built up and easily modified 2/42 Learning objectives · To create graphs used in manuscripts for epidemiology studies · To review and incorporate previously learned aspects of formatting graphs · To demonstrate novel data visualizations using Shiny 3/42 ggplot architecture review · Aesthetics: specify the variables to display - what are x and y? - can also link variables to color, shape, size and transparency · “geoms”: specify type of plot - do you want a scatter plot, line, bars, densities, or other type plot? · Scales: for transforming variables(e.g., log, sq. root). - also used to set legend – title, breaks, labels · Facets: creating separate panels for different factors · Themes: Adjust appearance: background, fonts, etc 4/42 Hemoglobin data · Data from the National Health and Nutritional Examination Survey (NHANES) dataset, 1999-2000 · containing data about n=3,990 patients · The file was created by merging demographic data with complete blood count file, and nutritional biochemistry lab file. · Contains measures hemoglobin, iron status, and other anemia- related parameters 5/42 Anemia data codebook · age = age in years of participant (years) · sex = sex of participant (Male vs Female) · tsat = transferrin saturation (%) · iron = total serum iron (ug/dL) · hgb = hemoglobin concentration (g/dL) · ferr = serum ferritin (mg/mL) · folate = serum folate (mg/mL) · race = participant race (Hispanic, White, Black, Other) · rdw = red cell distribution width (%) · wbc = white blood cell count (SI) · anemia = indicator variable for anemia (according to WHO definition) 6/42 Scatter plot review: hemoglobin by age, stratified by ethnicity and sex ggplot(data=anemia, aes(x=age,y=hgb,color=sex)) + geom_smooth() + geom_jitter(aes(size=1/iron), alpha=0.1) + xlab("Age")+ylab("Hemoglobin (g/dl)") + scale_size(name = "Iron Deficiency") + scale_color_discrete(name = "Sex") + facet_wrap(~race)+theme_bw() 7/42 Scatter plot review: hemoglobin by age, stratified by ethnicity and sex 8/42 Box plots ggplot(data=anemia, aes(x=race,y=hgb)) + geom_boxplot() 9/42 Box plots with points ggplot(data=anemia, aes(x=race,y=hgb,color=sex)) + geom_boxplot()+ geom_jitter(alpha=0.1) 10/42 Box plots with coordinates flipped ggplot(data=anemia, aes(x=race,y=hgb,color=sex)) + geom_boxplot()+ geom_jitter(alpha=0.1) + coord_flip() 11/42 Violin plots · Kernal density estimates that are placed on each side and mirrored so it forms a symmetrical shape · Easy to compare several distributions 12/42 Violin plots ggplot(data=anemia, aes(x=race,y=hgb,color=race)) + geom_violin() 13/42 Violin plots with underlying data points ggplot(data=anemia, aes(x=race,y=hgb,color=race)) + geom_violin()+ geom_jitter(alpha=0.1) 14/42 Violin plots stratified by 2 variables ggplot(data=anemia, aes(x=sex,y=hgb,color=race)) + geom_violin() 15/42 Violin plots & boxplot with no outliers ggplot(data=anemia, aes(x=race,y=hgb, color=race)) + geom_violin() + geom_boxplot(width=.1, fill="black", outlier.color=NA) + stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=2.5) 16/42 Practice · Use the anemia dataset to practice making scatterplots, boxplots, and violin plots · Try faceting, flipping orientation, changing colors and labels str(anemia) ## Classes 'tbl_df', 'tbl' and 'data.frame': 3990 obs. of 13 variables: ## $ age : num 77 49 59 43 37 70 81 38 85 23 ... ## $ sex : Factor w/ 2 levels "Male","Female": 1 1 2 1 1 1 1 2 2 2 ... ## $ tsat : num 16.3 41.5 27.6 28 19.7 18.5 16.9 27.1 13.4 35.8 ... ## $ iron : num 65 141 96 83 64 75 65 97 38 136 ... ## $ hgb : num 14.1 14.5 13.4 15.4 16 16.8 16.6 13.3 10.9 14.5 ... ## $ ferr : num 55 198 155 32 68 87 333 33 166 48 ... ## $ folate: num 24.6 17.1 12.2 13.5 23 46.9 14.6 6.1 30.3 19.9 ... ## $ vite : num 1488 1897 1311 528 3092 ... ## $ vita : num 74.9 84.6 54 41.9 72.5 ... ## $ race : Factor w/ 4 levels "Hispanic","White",..: 2 2 3 3 2 1 2 2 3 1 ... ## $ rdw : num 13.7 13.1 14.3 13.7 13.6 14.4 12.4 11.9 14.1 11.4 ... ## $ wbc : num 7.6 5.9 4.9 4.6 10.2 11.6 9.1 7.6 7.4 5.6 ... ## $ anemia: num 0 0 0 0 0 0 0 0 1 0 ... ## - attr(*, "na.action")=Class 'omit' Named int [1:805] 26 28 32 33 36 37 38 39 45 54 ... ## .. ..- attr(*, "names")= chr [1:805] "26" "28" "32" "33" ... 17/42 Forest plots · First gather the data into the proper format including the following variables: - Estimate - Lower CI - Upper CI - Grouping variable 18/42 Forest plots · For this example, we take the mean and calculate the upper and lower confidence interval for hemoglobin. · We will stack the row observations into one variable called "Type". anemia1 <- anemia %>% select(sex,hgb) %>% group_by(sex) %>% summarise_all(funs("mean",n(),lower=(mean-((sd(.)/sqrt(n()))*1.96)), upper=(mean+((sd(.)/sqrt(n()))*1.96)))) colnames(anemia1)[1] <- "Type" anemia2 <- anemia %>% select(race,hgb) %>% group_by(race) %>% summarise_all(funs("mean",n(),lower=(mean-((sd(.)/sqrt(n()))*1.96)), upper=(mean+((sd(.)/sqrt(n()))*1.96)))) colnames(anemia2)[1] <- "Type" anemia3 <- rbind(anemia1,anemia2) 19/42 Forest plots ggplot(data=anemia3, aes(x=Type, y=mean, ymin=lower, ymax=upper)) + geom_pointrange() 20/42 Forest plots: flip the axes, add labels ggplot(data=anemia3, aes(x=Type, y=mean, ymin=lower, ymax=upper)) + geom_pointrange(shape=20) + coord_flip() + xlab("Demographics") + ylab("Mean Hemoglobin (95% CI)") + theme_bw() 21/42 Forest plots: calculating mean and CI within ggplot · ggplot can calculate the mean and CI using stat_summary · Further data manipulation would be needed to stack multiple variables 22/42 Calculating mean and CI within ggplot ggplot(anemia, aes(x=race, y=hgb)) + stat_summary(fun.data=mean_cl_normal) + coord_flip() + theme_bw() + xlab("Demographics") + ylab("Mean Hemoglobin (95% CI)") 23/42 Forest plots: adding faceting ggplot(any.fit3, aes(x=V3, y=A1, ymin=lower, ymax=upper)) + geom_pointrange(shape=20) + coord_flip() + xlab("Predictor Variable") + ylab("Adjusted Risk Difference per 100 (95% CI)") + scale_y_continuous(breaks=c(-20,-15,-10,-5,0,5,10,15,20,25), limits = c(-21,26)) + theme_bw() + geom_hline(yintercept=0, lty=2) + facet_grid(setting~., scales= 'free', space='free') 24/42 25/42 Practice · Use the anemia dataset to practice making forest plots using other continuous variables · Use dplyr to create a new, categorized age variable (hint: factor this before graphing). Create a forest plot of mean hemoglobin by age category. 26/42 Kaplan-Meier plots - WIHS data · Women’s Interagency HIV Study (WIHS) is an ongoing observational cohort study with semiannual visits at 10 sites in the US · Data on 1,164 patients who were HIV-positive, free of clinical AIDS, and not on antiretroviral therapy (ART) at study baseline (Dec. 6, 1995) · Contains measures information on age, race, CD4 count, drug use, ARV treatment, and time to aids/death 27/42 Kaplan-Meier plots · MANY package options to plot survival functions · All use the survival package to calculate survival over time - survfit(survival) + survplot(rms) - ggkm(sachsmc/ggkm) & ggplot2 - ggkm(michaelway/ggkm) · Allows for multiple treatments and subgroups · Does not take into account competing risks 28/42 Kaplan-Meier example 1 · Calculate KM within ggplot · https://github.com/sachsmc/ggkm · Prep data wihs$outcome <- ifelse(is.na(wihs$art),0,1) wihs$time <- ifelse(is.na(wihs$aids_death_art), wihs$dropout,wihs$aids_death_art) wihs <- wihs %>% mutate(time = ifelse(is.na(time),study_end,time)) 29/42 KM plot within ggplot2 devtools::install_github("sachsmc/ggkm") library(ggkm) ggplot(wihs, aes(time = time, status = outcome)) + geom_km() 30/42 KM by treatment group ggplot(wihs, aes(time = time, status = outcome, color = factor(idu))) + geom_km() 31/42 Add confidence bands ggplot(wihs, aes(time = time, status = outcome, color = factor(idu))) + geom_km() + geom_kmband() 32/42 KM example #2 · Calculated using survival package · Plots KM curve with numbers at risk · Same package name as previous example! · https://github.com/michaelway/ggkm remove.packages("ggkm") install_github("michaelway/ggkm") library(ggkm) 33/42 KM example 2 fit <- survfit(Surv(time,outcome)~idu, data=wihs) ggkm(fit) 34/42 KM with numbers at risk ggkm(fit, table=TRUE, marks = FALSE, ystratalabs = c("No IDU", "History of IDU")) 35/42 Cumulative incidence plots · 1-survival probability · ipwrisk package - coming soon! - calculates adjusted cumulative incidence curves using IPTW - addresses censoring (IPCW) and competing risks - produces tables and graphics 36/42 Sankey diagram · Visualization that shows the flow of patients between states (over time) · States, or nodes, can be treatments, comorbidities, hospitalizations etc. · Paths connecting states are called links - proportion corresponds to thickness of line · Example: https://vizhub.healthdata.org/dex/ 37/42 Basic sankey diagrams in R library(networkD3) library(reshape2) library(magrittr) nodes <- data.frame(name=c("Renal Failure", "Hemodialysis at 6m", "Transplant at 6m", "Death by 6m", "Hemodialysis at 12m", "Transplant at 12m", "Death by 12m")) links <- data.frame(source=c(0,0,0,1,1,1,2,2,2,3), target=c(1,2,3,4,5,6,4,5,6,6), value=c(70,20,10,40,20,10,15,4,1,10)) sankeyNetwork(Links = links, Nodes = nodes, Source = "source", Target = "target", Value = "value", NodeID ="name", fontSize = 22, nodeWidth = 30,nodePadding = 5) 38/42 Basic sankey diagrams in R Hemodialysis at 12m Hemodialysis at 6m Renal Failure Transplant at 12m Transplant at 6m Death by 12m Death by 6m 39/42 Final Tips · Spend time planning your graph · Make sure to have the data in the correct structure before you start graphing · Start with a simple graph, gradually build in complexity 40/42 Further reading · ggplot2: http://docs.ggplot2.org/current/ · Cookbook for R: http://www.cookbook-r.com/Graphs/ · Quick-R: http://www.statmethods.net/index.html 41/42 Wrap-up · Questions? · Acknowledgements: Alan Brookhart, Sara Levintow · Contact info: [email protected] 42/42.
Recommended publications
  • Introduction to Ggplot2
    Introduction to ggplot2 Dawn Koffman Office of Population Research Princeton University January 2014 1 Part 1: Concepts and Terminology 2 R Package: ggplot2 Used to produce statistical graphics, author = Hadley Wickham "attempt to take the good things about base and lattice graphics and improve on them with a strong, underlying model " based on The Grammar of Graphics by Leland Wilkinson, 2005 "... describes the meaning of what we do when we construct statistical graphics ... More than a taxonomy ... Computational system based on the underlying mathematics of representing statistical functions of data." - does not limit developer to a set of pre-specified graphics adds some concepts to grammar which allow it to work well with R 3 qplot() ggplot2 provides two ways to produce plot objects: qplot() # quick plot – not covered in this workshop uses some concepts of The Grammar of Graphics, but doesn’t provide full capability and designed to be very similar to plot() and simple to use may make it easy to produce basic graphs but may delay understanding philosophy of ggplot2 ggplot() # grammar of graphics plot – focus of this workshop provides fuller implementation of The Grammar of Graphics may have steeper learning curve but allows much more flexibility when building graphs 4 Grammar Defines Components of Graphics data: in ggplot2, data must be stored as an R data frame coordinate system: describes 2-D space that data is projected onto - for example, Cartesian coordinates, polar coordinates, map projections, ... geoms: describe type of geometric objects that represent data - for example, points, lines, polygons, ... aesthetics: describe visual characteristics that represent data - for example, position, size, color, shape, transparency, fill scales: for each aesthetic, describe how visual characteristic is converted to display values - for example, log scales, color scales, size scales, shape scales, ..
    [Show full text]
  • Regression Models by Gretl and R Statistical Packages for Data Analysis in Marine Geology Polina Lemenkova
    Regression Models by Gretl and R Statistical Packages for Data Analysis in Marine Geology Polina Lemenkova To cite this version: Polina Lemenkova. Regression Models by Gretl and R Statistical Packages for Data Analysis in Marine Geology. International Journal of Environmental Trends (IJENT), 2019, 3 (1), pp.39 - 59. hal-02163671 HAL Id: hal-02163671 https://hal.archives-ouvertes.fr/hal-02163671 Submitted on 3 Jul 2019 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Distributed under a Creative Commons Attribution| 4.0 International License International Journal of Environmental Trends (IJENT) 2019: 3 (1),39-59 ISSN: 2602-4160 Research Article REGRESSION MODELS BY GRETL AND R STATISTICAL PACKAGES FOR DATA ANALYSIS IN MARINE GEOLOGY Polina Lemenkova 1* 1 ORCID ID number: 0000-0002-5759-1089. Ocean University of China, College of Marine Geo-sciences. 238 Songling Rd., 266100, Qingdao, Shandong, P. R. C. Tel.: +86-1768-554-1605. Abstract Received 3 May 2018 Gretl and R statistical libraries enables to perform data analysis using various algorithms, modules and functions. The case study of this research consists in geospatial analysis of Accepted the Mariana Trench, a hadal trench located in the Pacific Ocean.
    [Show full text]
  • Julia: a Fresh Approach to Numerical Computing∗
    SIAM REVIEW c 2017 Society for Industrial and Applied Mathematics Vol. 59, No. 1, pp. 65–98 Julia: A Fresh Approach to Numerical Computing∗ Jeff Bezansony Alan Edelmanz Stefan Karpinskix Viral B. Shahy Abstract. Bridging cultures that have often been distant, Julia combines expertise from the diverse fields of computer science and computational science to create a new approach to numerical computing. Julia is designed to be easy and fast and questions notions generally held to be \laws of nature" by practitioners of numerical computing: 1. High-level dynamic programs have to be slow. 2. One must prototype in one language and then rewrite in another language for speed or deployment. 3. There are parts of a system appropriate for the programmer, and other parts that are best left untouched as they have been built by the experts. We introduce the Julia programming language and its design|a dance between special- ization and abstraction. Specialization allows for custom treatment. Multiple dispatch, a technique from computer science, picks the right algorithm for the right circumstance. Abstraction, which is what good computation is really about, recognizes what remains the same after differences are stripped away. Abstractions in mathematics are captured as code through another technique from computer science, generic programming. Julia shows that one can achieve machine performance without sacrificing human con- venience. Key words. Julia, numerical, scientific computing, parallel AMS subject classifications. 68N15, 65Y05, 97P40 DOI. 10.1137/141000671 Contents 1 Scientific Computing Languages: The Julia Innovation 66 1.1 Julia Architecture and Language Design Philosophy . 67 ∗Received by the editors December 18, 2014; accepted for publication (in revised form) December 16, 2015; published electronically February 7, 2017.
    [Show full text]
  • Revolution R Enterprise™ 7.1 Getting Started Guide
    Revolution R Enterprise™ 7.1 Getting Started Guide The correct bibliographic citation for this manual is as follows: Revolution Analytics, Inc. 2014. Revolution R Enterprise 7.1 Getting Started Guide. Revolution Analytics, Inc., Mountain View, CA. Revolution R Enterprise 7.1 Getting Started Guide Copyright © 2014 Revolution Analytics, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Revolution Analytics. U.S. Government Restricted Rights Notice: Use, duplication, or disclosure of this software and related documentation by the Government is subject to restrictions as set forth in subdivision (c) (1) (ii) of The Rights in Technical Data and Computer Software clause at 52.227-7013. Revolution R, Revolution R Enterprise, RPE, RevoScaleR, RevoDeployR, RevoTreeView, and Revolution Analytics are trademarks of Revolution Analytics. Other product names mentioned herein are used for identification purposes only and may be trademarks of their respective owners. Revolution Analytics. 2570 W. El Camino Real Suite 222 Mountain View, CA 94040 USA. Revised on March 3, 2014 We want our documentation to be useful, and we want it to address your needs. If you have comments on this or any Revolution document, send e-mail to [email protected]. We’d love to hear from you. Contents Chapter 1. What Is Revolution R Enterprise? ....................................................................
    [Show full text]
  • Julia: a Modern Language for Modern ML
    Julia: A modern language for modern ML Dr. Viral Shah and Dr. Simon Byrne www.juliacomputing.com What we do: Modernize Technical Computing Today’s technical computing landscape: • Develop new learning algorithms • Run them in parallel on large datasets • Leverage accelerators like GPUs, Xeon Phis • Embed into intelligent products “Business as usual” will simply not do! General Micro-benchmarks: Julia performs almost as fast as C • 10X faster than Python • 100X faster than R & MATLAB Performance benchmark relative to C. A value of 1 means as fast as C. Lower values are better. A real application: Gillespie simulations in systems biology 745x faster than R • Gillespie simulations are used in the field of drug discovery. • Also used for simulations of epidemiological models to study disease propagation • Julia package (Gillespie.jl) is the state of the art in Gillespie simulations • https://github.com/openjournals/joss- papers/blob/master/joss.00042/10.21105.joss.00042.pdf Implementation Time per simulation (ms) R (GillespieSSA) 894.25 R (handcoded) 1087.94 Rcpp (handcoded) 1.31 Julia (Gillespie.jl) 3.99 Julia (Gillespie.jl, passing object) 1.78 Julia (handcoded) 1.2 Those who convert ideas to products fastest will win Computer Quants develop Scientists prepare algorithms The last 25 years for production (Python, R, SAS, DEPLOY (C++, C#, Java) Matlab) Quants and Computer Compress the Scientists DEPLOY innovation cycle collaborate on one platform - JULIA with Julia Julia offers competitive advantages to its users Julia is poised to become one of the Thank you for Julia. Yo u ' v e k i n d l ed leading tools deployed by developers serious excitement.
    [Show full text]
  • Download from a Repository for Fur- Should Be Conducted When Deemed Appropriate by Pub- Ther Development Or Customisation
    Smith and Hayward BMC Infectious Diseases (2016) 16:145 DOI 10.1186/s12879-016-1475-5 SOFTWARE Open Access DotMapper: an open source tool for creating interactive disease point maps Catherine M. Smith* and Andrew C. Hayward Abstract Background: Molecular strain typing of tuberculosis isolates has led to increased understanding of the epidemiological characteristics of the disease and improvements in its control, diagnosis and treatment. However, molecular cluster investigations, which aim to detect previously unidentified cases, remain challenging. Interactive dot mapping is a simple approach which could aid investigations by highlighting cases likely to share epidemiological links. Current tools generally require technical expertise or lack interactivity. Results: We designed a flexible application for producing disease dot maps using Shiny, a web application framework for the statistical software, R. The application displays locations of cases on an interactive map colour coded according to levels of categorical variables such as demographics and risk factors. Cases can be filtered by selecting combinations of these characteristics and by notification date. It can be used to rapidly identify geographic patterns amongst cases in molecular clusters of tuberculosis in space and time; generate hypotheses about disease transmission; identify outliers, and guide targeted control measures. Conclusions: DotMapper is a user-friendly application which enables rapid production of maps displaying locations of cases and their epidemiological characteristics without the need for specialist training in geographic information systems. Enhanced understanding of tuberculosis transmission using this application could facilitate improved detection of cases with epidemiological links and therefore lessen the public health impacts of the disease. It is a flexible system and also has broad international potential application to other investigations using geo-coded health information.
    [Show full text]
  • Gramm: Grammar of Graphics Plotting in Matlab
    Gramm: grammar of graphics plotting in Matlab Pierre Morel1 DOI: 10.21105/joss.00568 1 German Primate Center, Göttingen, Germany Software • Review Summary • Repository • Archive Gramm is a data visualization toolbox for Matlab (The MathWorks Inc., Natick, USA) Submitted: 31 January 2018 that allows to produce publication-quality plots from grouped data easily and flexibly. Published: 06 March 2018 Matlab can be used for complex data analysis using a high-level interface: it supports mixed-type tabular data via tables, provides statistical functions that accept these tables Licence Authors of JOSS papers retain as arguments, and allows users to adopt a split-apply-combine approach (Wickham 2011) copyright and release the work un- with rowfun(). However, the standard plotting functionality in Matlab is mostly low- der a Creative Commons Attri- level, allowing to create axes in figure windows and draw geometric primitives (lines, bution 4.0 International License points, patches) or simple statistical visualizations (histograms, boxplots) from numerical (CC-BY). array data. Producing complex plots from grouped data thus requires iterating over the various groups in order to make successive statistical computations and low-level draw calls, all the while handling axis and color generation in order to visually separate data by groups. The corresponding code is often long, not easily reusable, and makes exploring alternative plot designs tedious (Example code Fig. 1A). Inspired by ggplot2 (Wickham 2009), the R implementation of “grammar of graphics” principles (Wilkinson 1999), gramm improves Matlab’s plotting functionality, allowing to generate complex figures using high-level object-oriented code (Example code Figure 1B). Gramm has been used in several publications in the field of neuroscience, from human psychophysics (Morel, Ulbrich, and Gail 2017), to electrophysiology (Morel et al.
    [Show full text]
  • Figure Properties in Matlab
    Figure Properties In Matlab Which Quentin misquote so correctly that Wojciech kayaks her alkyne? Unrefreshing and unprepared Werner composts her dialects proventriculuses wyte and fidging roundly. Imperforate Sergei coaxes, his sulks subcontract saddled brazenly. This from differential equations in matlab color in figure properties or use git or measurement unit specify the number If your current axes. Note how does temperature approaches a specific objects on a node pointer within a hosting control. Matlab simulink simulink with a plot data values associated with other readers with multiple data set with block diagram. This video explains plot and subplot command and comprehend various features and properties matlab2tikz converts most MATLABR figures including 2D and 3D plots. This effect on those available pixel format function block amplifies this will cover more about polar plots to another. The dimension above idea a polar plot behind the polar equation, along a cardioid. Each part than a matlab plot held some free of properties that tug be changed to. To alternate select an isovalue within long range of values in mere volume data. To applied thermodynamics. While you place using appropriate axes properties, television shows matlab selects a series using. As shown in Figure 1 we showcase a ggplot2 plot brought a legend with by previous R. Code used as a ui figure. Bar matlab 3storemelitoit. In polar plot, you can get information about properties we are a property value ie; we have their respective companies use this allows matrix as. Komutu yazıp enter tuşuna bastıktan sonra aşağıdaki pencere açılır.
    [Show full text]
  • Data Visualization with Ggplot2 : : CHEAT SHEET
    Data Visualization with ggplot2 : : CHEAT SHEET Use a geom function to represent data points, use the geom’s aesthetic properties to represent variables. Basics Geoms Each function returns a layer. GRAPHICAL PRIMITIVES TWO VARIABLES ggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same a <- ggplot(economics, aes(date, unemploy)) continuous x , continuous y continuous bivariate distribution components: a data set, a coordinate system, b <- ggplot(seals, aes(x = long, y = lat)) e <- ggplot(mpg, aes(cty, hwy)) h <- ggplot(diamonds, aes(carat, price)) and geoms—visual marks that represent data points. a + geom_blank() e + geom_label(aes(label = cty), nudge_x = 1, h + geom_bin2d(binwidth = c(0.25, 500)) (Useful for expanding limits) nudge_y = 1, check_overlap = TRUE) x, y, label, x, y, alpha, color, fill, linetype, size, weight alpha, angle, color, family, fontface, hjust, F M A b + geom_curve(aes(yend = lat + 1, lineheight, size, vjust h + geom_density2d() xend=long+1,curvature=z)) - x, xend, y, yend, x, y, alpha, colour, group, linetype, size + = alpha, angle, color, curvature, linetype, size e + geom_jitter(height = 2, width = 2) x, y, alpha, color, fill, shape, size data geom coordinate plot a + geom_path(lineend="butt", linejoin="round", h + geom_hex() x = F · y = A system linemitre=1) e + geom_point(), x, y, alpha, color, fill, shape, x, y, alpha, colour, fill, size x, y, alpha, color, group, linetype, size size, stroke To display values, map variables in the data to visual a + geom_polygon(aes(group = group)) e + geom_quantile(), x, y, alpha, color, group, properties of the geom (aesthetics) like size, color, and x x, y, alpha, color, fill, group, linetype, size linetype, size, weight continuous function and y locations.
    [Show full text]
  • JASP: Graphical Statistical Software for Common Statistical Designs
    JSS Journal of Statistical Software January 2019, Volume 88, Issue 2. doi: 10.18637/jss.v088.i02 JASP: Graphical Statistical Software for Common Statistical Designs Jonathon Love Ravi Selker Maarten Marsman University of Newcastle University of Amsterdam University of Amsterdam Tahira Jamil Damian Dropmann Josine Verhagen University of Amsterdam University of Amsterdam University of Amsterdam Alexander Ly Quentin F. Gronau Martin Šmíra University of Amsterdam University of Amsterdam Masaryk University Sacha Epskamp Dora Matzke Anneliese Wild University of Amsterdam University of Amsterdam University of Amsterdam Patrick Knight Jeffrey N. Rouder Richard D. Morey University of Amsterdam University of California, Irvine Cardiff University University of Missouri Eric-Jan Wagenmakers University of Amsterdam Abstract This paper introduces JASP, a free graphical software package for basic statistical pro- cedures such as t tests, ANOVAs, linear regression models, and analyses of contingency tables. JASP is open-source and differentiates itself from existing open-source solutions in two ways. First, JASP provides several innovations in user interface design; specifically, results are provided immediately as the user makes changes to options, output is attrac- tive, minimalist, and designed around the principle of progressive disclosure, and analyses can be peer reviewed without requiring a “syntax”. Second, JASP provides some of the recent developments in Bayesian hypothesis testing and Bayesian parameter estimation. The ease with which these relatively complex Bayesian techniques are available in JASP encourages their broader adoption and furthers a more inclusive statistical reporting prac- tice. The JASP analyses are implemented in R and a series of R packages. Keywords: JASP, statistical software, Bayesian inference, graphical user interface, basic statis- tics.
    [Show full text]
  • Exploring Technology Trends in Data Journalism a Content Analysis of CAR Conference Session Descriptions
    R Rising? Exploring Technology Trends in Data Journalism A Content Analysis of CAR Conference Session Descriptions Erica Yee Khoury College of Computer Sciences Northeastern University Boston, MA, USA [email protected] ABSTRACT Understanding a technology landscape: Previous research has endeavored to understand the overall technology landscape for The evolving field of data journalism has been the subject of some computer programmers. Multiple studies have mined data from the scholarship, but no systematic analysis of specific technologies community question answering site Stack Overflow, with results used. This study builds on previous surveys and case studies of showing that a mined technology landscape can provide an newsrooms by discovering trends in software and programming aggregated view of a wide range of relationships and trends [5], languages used by practitioners. Keyword discovery is performed especially relative popularity of languages [6]. Other researchers to assess the popularity of such tools in the data journalism domain, have explored the popularity of programming languages based on under the assumption that topics discussed at the major conference data from GitHub, a popular social, distributed version control in the field reflect technologies used by practitioners. The collected system. One study analyzing the state of GitHub spanning 2007- and categorized data enables time trend analyses and 2014 and 16 million repositories found JavaScript to be the most recommendations for practitioners and students based on the popular language by a far margin, followed by Ruby and Python current technology landscape. While certain technologies can fall [7]. out of favor, results suggest the software Microsoft Excel and Information extraction methods: Information extraction (IE) programming languages Python, SQL, R and JavaScript have been is used to locate specific pieces of data from a corpus of natural- used consistently by data journalists over the last five years.
    [Show full text]
  • An Introduction to R Graphics 4. Ggplot2
    Data Visualization in R 4. ggplot2 Michael Friendly SCS Short Course Sep/Oct, 2018 http://www.datavis.ca/courses/RGraphics/ Resources: Books Hadley Wickham, ggplot2: Elegant graphics for data analysis, 2nd Ed. 1st Ed: Online, http://ggplot2.org/book/ ggplot2 Quick Reference: http://sape.inf.usi.ch/quick-reference/ggplot2/ Complete ggplot2 documentation: http://docs.ggplot2.org/current/ Winston Chang, R Graphics Cookbook: Practical Recipes for Visualizing Data Cookbook format, covering common graphing tasks; the main focus is on ggplot2 R code from book: http://www.cookbook-r.com/Graphs/ Download from: http://ase.tufts.edu/bugs/guide/assets/R%20Graphics%20Cookbook.pdf Antony Unwin, Graphical Data Analysis with R R code: http://www.gradaanwr.net/ 2 Resources: Cheat sheets • Data visualization with ggplot2: https://www.rstudio.com/wp-content/uploads/2016/11/ggplot2- cheatsheet-2.1.pdf • Data transformation with dplyr: https://github.com/rstudio/cheatsheets/raw/master/source/pdfs/data- transformation-cheatsheet.pdf 3 What is ggplot2? • ggplot2 is Hadley Wickham’s R package for producing “elegant graphics for data analysis” . It is an implementation of many of the ideas for graphics introduced in Lee Wilkinson’s Grammar of Graphics . These ideas and the syntax of ggplot2 help to think of graphs in a new and more general way . Produces pleasing plots, taking care of many of the fiddly details (legends, axes, colors, …) . It is built upon the “grid” graphics system . It is open software, with a large number of gg_ extensions. See: http://www.ggplot2-exts.org/gallery/ 4 Follow along • From the course web page, click on the script gg-cars.R, http://www.datavis.ca/courses/RGraphics/R/gg-cars.R • Select all (ctrl+A) and copy (ctrl+C) to the clipboard • In R Studio, open a new R script file (ctrl+shift+N) • Paste the contents (ctrl+V) • Run the lines (ctrl+Enter) to along with me ggplot2 vs base graphics Some things that should be simple are harder than you’d like in base graphics Here, I’m plotting gas mileage (mpg) vs.
    [Show full text]