The Basics of Plotting in R

Similar documents
Intro to R Graphics Center for Social Science Computation and Research, 2010 Stephanie Lee, Dept of Sociology, University of Washington

Statistics 251: Statistical Methods

An Introduction to R Graphics

MATH11400 Statistics Homepage

CMPSC 390 Visual Computing Spring 2014 Bob Roos Notes on R Graphs, Part 2

DSCI 325: Handout 18 Introduction to Graphics in R

Intro to R for Epidemiologists

An Introduction to R 2.2 Statistical graphics

Using Built-in Plotting Functions

R Visualizing Data. Fall Fall 2016 CS130 - Intro to R 1

Introduction to R: Day 2 September 20, 2017

Statistical Programming with R

Introduction to R for Epidemiologists

Interactive Scatterplots

INTRODUCTION TO R. Basic Graphics

Spring 2017 CS130 - Intro to R 1 R VISUALIZING DATA. Spring 2017 CS130 - Intro to R 2

Advanced Statistics 1. Lab 11 - Charts for three or more variables. Systems modelling and data analysis 2016/2017

Package beanplot. R topics documented: February 19, Type Package

R Workshop Module 3: Plotting Data Katherine Thompson Department of Statistics, University of Kentucky

Bar Charts and Frequency Distributions

12. A(n) is the number of times an item or number occurs in a data set.

Name Date Types of Graphs and Creating Graphs Notes

CIND123 Module 6.2 Screen Capture

Chapter 2 Descriptive Statistics. Tabular and Graphical Presentations

Dr. Junchao Xia Center of Biophysics and Computational Biology. Fall /6/ /13

Introduction to R and Statistical Data Analysis

Package FCGR. October 13, 2015

Organizing and Summarizing Data

Rstudio GGPLOT2. Preparations. The first plot: Hello world! W2018 RENR690 Zihaohan Sang

Plotting Complex Figures Using R. Simon Andrews v

AA BB CC DD EE. Introduction to Graphics in R

Exploratory Data Analysis September 8, 2010

Combo Charts. Chapter 145. Introduction. Data Structure. Procedure Options

Ch. 1.4 Histograms & Stem-&-Leaf Plots

Error-Bar Charts from Summary Data

Package sciplot. February 15, 2013

Graphics in R Ira Sharenow January 2, 2019

Week 2 Basic Statistical Concepts, Part II

NCSS Statistical Software

A Populous Place State Pie Chart

r2excel: Read, write and format easily Excel files using R software

Data Visualization. Andrew Jaffe Instructor

Basic Statistical Graphics in R. Stem and leaf plots 100,100,100,99,98,97,96,94,94,87,83,82,77,75,75,73,71,66,63,55,55,55,51,19

Graphics in R STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley

MICROSOFT EXCEL BUILDING GRAPHS

Section 2-2 Frequency Distributions. Copyright 2010, 2007, 2004 Pearson Education, Inc

IST 3108 Data Analysis and Graphics Using R Week 9

Section Frequency Distribution and Statistical Graphs. Copyright 2013, 2010, 2007, Pearson, Education, Inc.

Module 10. Data Visualization. Andrew Jaffe Instructor

STAT STATISTICAL METHODS. Statistics: The science of using data to make decisions and draw conclusions

Chapter 2 - Graphical Summaries of Data

8. MINITAB COMMANDS WEEK-BY-WEEK

[POLS 8500] Stochastic Gradient Descent, Linear Model Selection and Regularization

7/18/16. Review. Review of Homework. Lecture 3: Programming Statistics in R. Questions from last lecture? Problems with Stata? Problems with Excel?

Graph tool instructions and R code

LESSON 14: Box plots questions

Chapter 1, TUFTE STYLE GRIDDING FOR READABILITY. Chapter 5, SLICE (CROSS-SECTIONAL VIEWS)

Math 227 EXCEL / MEGASTAT Guide

Elementary Statistics. Chapter 2 Review: Summarizing & Graphing Data

MATH1635, Statistics (2)

Chapter 2: Descriptive Statistics

Chapter 1: Overview and Descriptive Statistics

Practical 2: Plotting

SPSS. (Statistical Packages for the Social Sciences)

Az R adatelemzési nyelv

Exploratory Data Analysis - Part 2 September 8, 2005

1.2. Pictorial and Tabular Methods in Descriptive Statistics

Brief Guide on Using SPSS 10.0

Creating a Basic Chart in Excel 2007

Visualizing Data: Freq. Tables, Histograms

Lesson 18-1 Lesson Lesson 18-1 Lesson Lesson 18-2 Lesson 18-2

Overview. Frequency Distributions. Chapter 2 Summarizing & Graphing Data. Descriptive Statistics. Inferential Statistics. Frequency Distribution

Statistical Programming Camp: An Introduction to R

Add to the ArcMap layout the Census dataset which are located in your Census folder.

Statistical Graphs & Charts

Data Handling. Moving from A to A* Calculate the numbers to be surveyed for a stratified sample (A)

Univariate Data - 2. Numeric Summaries

Test Bank for Privitera, Statistics for the Behavioral Sciences

2.4-Statistical Graphs

The foundations of building Tableau visualizations and Dashboards

Key Terms. Symbology. Categorical attributes. Style. Layer file

CREATE AN EFFECTIVE POSTER

Middle Years Data Analysis Display Methods

Topic (3) SUMMARIZING DATA - TABLES AND GRAPHICS

Chuck Cartledge, PhD. 20 January 2018

Boxplot

PRACTICE EXERCISES. Family Utility Expenses

CHAPTER 2 Information processing (Units 3 and 4)

4 Displaying Multiway Tables

Parents Names Mom Cell/Work # Dad Cell/Work # Parent List the Math Courses you have taken and the grade you received 1 st 2 nd 3 rd 4th

DATA VISUALIZATION WITH GGPLOT2. Grid Graphics

Chapter 2: Descriptive Statistics: Tabular and Graphical Methods

Basics of Plotting Data

Install RStudio from - use the standard installation.

Data Mining - Data. Dr. Jean-Michel RICHER Dr. Jean-Michel RICHER Data Mining - Data 1 / 47

LAB 1: Graphical Descriptions of Data

> glucose = c(81, 85, 93, 93, 99, 76, 75, 84, 78, 84, 81, 82, 89, + 81, 96, 82, 74, 70, 84, 86, 80, 70, 131, 75, 88, 102, 115, + 89, 82, 79, 106)

Mathematics 47: Lecture 2

Package areaplot. October 18, 2017

Abbreviated Title of Report. Table of Contents USING THIS DOCUMENT...2 SDWP REPORT FORMATTING...2 Charts...3 Tables...9 APPENDIX A...

Transcription:

The Basics of Plotting in R

R has a built-in Datasets Package: iris mtcars precip faithful state.x77 USArrests presidents ToothGrowth USJudgeRatings You can call built-in functions like hist() or plot() on a built-in data set to quickly produce a chart

Basic plotting in R hist(nhtemp) plot(nhtemp)

Basic plotting in R attach(iris) plot(petal.length ~ Petal.Width)

Basic plotting in R attach(iris) plot(petal.length ~ Petal.Width, col = Species)

Basic plotting in R plot(petal.length ~ Petal.Width, col = Species, main = Iris: Petal width vs. length )

Legends legend("topleft", legend = unique(species), fill = unique(species))

Basic plotting in R attach(faithful) duration = eruptions plot(duration, waiting, xlab = "Eruption duration in minutes", ylab = "Time waited in minutes") plot(duration, waiting, xlab = "Eruption duration in minutes", ylab = "Time waited in minutes", col = "seagreen")

Histograms hist(waiting) hist(eruptions)

Histograms hist(waiting, breaks = 5) hist(waiting, breaks = 20)

Histograms hist(waiting, main = "Old Faithful", cex.main = 1.75, xlab = "Waiting Time in Minutes", ylab = "Frequency", cex.lab = 1.25)

Histograms hist(waiting, main = "Old Faithful", cex.main = 1.75, xlab = "Waiting Time in Minutes", ylab = "Frequency", cex.lab = 1.25 col = "blue", border = "orange")

Stem and leaf plot > stem(waiting) The decimal point is 1 digit(s) to the right of the 4 3 4 55566666777788899999 5 00000111111222223333333444444444 5 555555666677788889999999 6 00000022223334444 6 555667899 7 00001111123333333444444 7 555555556666666667777777777778888888888888889999999999 8 000000001111111111111222222222222333333333333334444444444 8 55555566666677888888999 9 00000012334 9 6

> stem(eruptions) The decimal point is 1 digit(s) to the left of the 16 070355555588 18 000022233333335577777777888822335777888 20 00002223378800035778 22 0002335578023578 24 00228 26 23 28 080 30 7 32 2337 34 250077 36 0000823577 38 2333335582225577 40 0000003357788888002233555577778 42 03335555778800233333555577778 44 02222335557780000000023333357778888 46 0000233357700000023578 48 00000022335800333 50 0370

Bar charts > races_younger [1] "Black" "Hispanic" "Other" "White" > population_in_millions_younger [1] 10.76 19.03 7.76 40.50 > barplot(population_in_millions_younger, names.arg = races_younger, main = "Younger than 18, 2014", ylab = "Population in Millions")

Bar charts > races_all [1] "Native" "Asian" "Black" "Hispanic" "Two" "White" > population_in_millions_all [1] 1.39 18.12 38.60 55.61 5.67 195.35 barplot(population_in_millions_all, names.arg = races_all, main = "All ages, 2014", ylab = "Population in Millions")

Bar charts > races_all_other [1] "Black" "Hispanic" "White" "Other" > population_in_millions_all_other [1] 38.60 55.61 195.35 25.19 barplot(population_in_millions_all_other, names.arg = races_all_other, main = "All ages, 2014", ylab = "Population in Millions")

Stacked and grouped bar charts

Pie charts pie_labels_younger <- paste(races_younger, population_in_millions_younger, sep = "\n") pie(population_in_millions_younger, main = "Younger than 18\nPopulation in Millions", labels = pie_labels_younger)

Pie charts pie_labels_all_other <- paste(races_all_other, population_in_millions_all_other, sep = "\n") pie(population_in_millions_all_other, main = "All Ages\nPopulation in Millions", labels = pie_labels_all_other)

Pie charts

Dot plots states <- data.frame(state.x77) sorted_states <- states[order(states$income), ] dotchart(sorted_states$income, rownames(sorted_states), cex.lab =.25, main = "Income per capita")

Box plots boxplot(petal.length ~ Species, main = "Iris Petal Length by Species", xlab = "Species", ylab = "Petal Length")

Notched Box plots attach(toothgrowth) boxplot(len ~ supp * dose, data = Toothgrowth, notch = TRUE, col = (c("gold", "darkgreen")), main = "Tooth Growth", xlab = "Supplement and Dose") If the notches do not overlap, then the medians of the groups are different (because their confidence intervals do not overlap).

Simple Scatterplots plot(usjudgeratings$rten ~ USJudgeRatings$FAMI, xlab = "Familiarity with Law", ylab = "Worthy of Retention", main = "Law Familiarity vs. Worthy of Retention", pch = "+")

Scatterplot Matrices CONT Number of contacts of lawyer with judge. INTG Judicial integrity. DMNR Demeanor. DILG Diligence. pairs(~usjudgeratings$cont + USJudgeRatings$INTG + USJudgeRatings$DMNR + USJudgeRatings$DILG, main = "US Judge Ratings")

Scatterplot Matrices features <- c("contacts", "Integrity", "Demeanor", "Diligence") pairs(~usjudgeratings$cont + USJudgeRatings$INTG + USJudgeRatings$DMNR + USJudgeRatings$DILG, labels = features, main = "US Judge Ratings")

3D Scatterplots library(scatterplot3d) scatterplot3d(mtcars$wt, mtcars$disp, mtcars$mpg, main = "3D Scatterplot")

Graphical parameters Text and symbol size (cex:.axis,.lab,.main) Fonts (font:.axis,.lab,.main): 1=plain, 2=bold, 3=italic, 4=bold italic, 5=symbol Colors (col): colors, and more colors http://www.statmethods.net/advgraphs/parameters.html

Graphical parameters (cont d) Plotting symbols (pch) Line type (lty)