0% found this document useful (0 votes)
35 views

Introduction To R: Basic Graphics

This document introduces basic graphics in R. It discusses the graphics package and functions like plot() and hist() for creating plots from data. Plot() can take vectors, linear models, or other inputs to create different plot types like scatter plots, histograms, or plots with categorical variables. Hist() creates a histogram to visualize the distribution of a variable. Other functions mentioned include barplot(), boxplot(), and pairs(). Examples use the countries data frame to demonstrate plotting population vs. area and other variable combinations.

Uploaded by

seggy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Introduction To R: Basic Graphics

This document introduces basic graphics in R. It discusses the graphics package and functions like plot() and hist() for creating plots from data. Plot() can take vectors, linear models, or other inputs to create different plot types like scatter plots, histograms, or plots with categorical variables. Hist() creates a histogram to visualize the distribution of a variable. Other functions mentioned include barplot(), boxplot(), and pairs(). Examples use the countries data frame to demonstrate plotting population vs. area and other variable combinations.

Uploaded by

seggy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

INTRODUCTION TO R

Basic Graphics

Introduction to R

Graphics in R

Create plots with code

Replication and modication easy

Reproducibility!

graphics package

ggplot2, ggvis, lattice

Introduction to R

graphics package

Many functions

plot() and hist()

plot()

Generic

Dierent inputs -> Dierent plots

Vectors, linear models, kernel densities

Introduction to R

countries
> str(countries)
'data.frame': 194 obs. of 5 variables:
$ name
: chr "Afghanistan" "Albania" "Algeria" ...
$ continent : Factor w/ 6 levels "Africa","Asia", ...
$ area
: int 648 29 2388 0 0 1247 0 0 2777 2777 ...
$ population: int 16 3 20 0 0 7 0 0 28 28 ...
$ religion : Factor w/ 6 levels "Buddhist","Catholic" ...

Introduction to R

plot() (categorical)
> plot(countries$continent)

Introduction to R

plot() (numerical)
> plot(countries$population)

Introduction to R

plot() (2x numerical)


> plot(countries$area, countries$population)

Introduction to R

plot() (2x numerical)


> plot(log(countries$area), log(countries$population))

Introduction to R

plot() (2x categorical)


> plot(countries$continent, countries$religion)

Introduction to R

plot() (2x categorical)


x axis (horizontal)
y axis (vertical)
> plot(countries$religion, countries$continent)

Introduction to R

hist()

Short for histogram

Visual representation of distribution

Bin all values

Plot frequency of bins

Introduction to R

hist()
> africa_obs <- countries$continent == "Africa"
> africa <- countries[africa_obs, ]

Introduction to R

hist()
> hist(africa$population)

Introduction to R

hist()
> hist(africa$population, breaks = 10)

Introduction to R

Other graphics functions

barplot()

boxplot()

pairs()

INTRODUCTION TO R

Lets practice!

You might also like