Scaling in R

10
Scaling in R & ggplot + forecast Ed Goodwin Houston R Users Group

Transcript of Scaling in R

Page 1: Scaling in R

Scaling in R &

ggplot + forecastEd Goodwin

Houston R Users Group

Page 2: Scaling in R

What is scaling?Scaling is when you need to transform a dataset to

another size scale…usually to analyze with a another data set

Example: comparing two survey datasets with different scoring mechanisms

It allows you to measure the relative effects of datasets on different scales

Page 3: Scaling in R

Let’s make some samples

Page 4: Scaling in R

How do we common-size our samples?

• With the scale( ) function

• scale( ) allows you to scale and center the data

Page 5: Scaling in R

Scaling

Divide all column values by the standard deviation

to arrive at a common scaling

Page 6: Scaling in R

Centering

Subtract all column values from the column mean to

get a common center value

Page 7: Scaling in R

Centered & Scaled

Page 8: Scaling in R

You could also do this yourself (z-transform)

Page 9: Scaling in R

Forecast + ggplot

Recent updates to Rob Hyndman’s forecast package include ability to use ggplot for plotting time series forecasts.

See http://robjhyndman.com/hyndsight/forecast7-ggplot2/ for more details

Page 10: Scaling in R

Using ggplot with time seriesuse autoplot( ) function with time series objects to create ggplot graphics.