Presentation is loading. Please wait.

Presentation is loading. Please wait.

R Visualization with ggplot

Similar presentations


Presentation on theme: "R Visualization with ggplot"— Presentation transcript:

1 R Visualization with ggplot

2 What is ggplot? Package specifically for data visualization
Created by Hadley Wickham in 2005 (Rice professor!!!!) Open source, most popular visualization tool in R ggplot2 extension

3 Key Distinguishing features
ggplot2 allows the user to add, remove or alter components in a plot at a high level of abstraction More complexity in visualization schemes available compared to base R functions

4 ggplot2 examples

5 Plot vs ggplot

6 The different parts to the plotting function we will cover today
Data Aesthetic Mappings Geometric Objects Statistical Transformations Scales

7 Loading it into R

8 Analyzing the data we will use today

9 Basic Plots (data)

10 Basic Plots (data)

11 Instead of using qplot, use ggplot for the two examples I showed previously

12 Your Turn! Create a qplot of Old Faithful’s eruption time vs. waiting time

13 Aesthetic Inputs ggplot will not work unless there are a set of aesthetic inputs color, size, and shape (visual properties that affect the display) Other plot functions don’t have this issue because they don’t have specific inputs for display characteristics

14 Aesthetics Color (Still qplot)
The color input allows you to distinguish your data by color gradients

15 Aesthetics Color (Still qplot)

16 Aesthetics Color (Still qplot)
For just one color, use the I() notation

17 Your Turn! Make a plot of old faithful’s eruptions vs waiting time with all the points orange Change the color to the value of eruption time

18 Aesthetics Shape (Still qplot)
The shape of the individual points on the plot can also be changed and utilized to reflect data characteristics

19 Aesthetics Size (Still qplot)
Same can be done with the size of the points

20 Aesthetics Size (Still qplot)
To make the previous slide look better, we can combine input parameters

21 Aesthetics Size (Still qplot)
For just one size, use the I() notation

22 Your Turn Spend two to three minutes playing around with different sizing, shapes, and coloring with the mpg and airquality data set Airquality dataset is new. Spend some time to familiarize yourself with it

23 Aesthetics for ggplot The key difference between ggplot and qplot is the x and y coordinate values are included in specified aesthetic arguments

24 Aesthetics for ggplot Notice the different methods of aesthetic arguments in ggplot

25 Aesthetics for ggplot

26 Your Turn! Use ggplot to do the same old faithful plot we’ve been using (color is orange)

27 Your Turn! Now with the airquality data, use ggplot to plot ozone vs temp with color as the month and size as the day

28 Statistical Plotting (white noise)
You can add ‘white noise’ to the data as well as modify the data for more accurate analysis through the geom argument

29 Statistical Plotting (boxplot)

30 Your Turn Produce a jittery plot of the ozone vs temperature in the airquality data set Make a boxplot

31 Statistical Plotting (geom)
Notice the different methods of inputting geom arguments in ggplot

32 Statistical Plotting (geom boxplot)

33 Your Turn Use ggplot to make the same plots you made previously of airquality

34 Statistical Plotting (geom freqpoly)

35 Statistical Plotting (geom histogram)
You can alter the characteristics of display within statistical plots

36 Statistical Plotting (geom histogram)

37 Statistical Plotting (geom density)
Utilizing geom parameters with color/other aesthetic parameters can help differentiate between data

38 Statistical Plotting (adding lines for analysis)

39 Statistical Plotting (adding lines for analysis)
This one makes more sense

40 Labels (qplot)

41 Labels (ggplot)

42 Your Final Turn! Create some nice cool-looking plots of the airquality dataset (keep in mind the plots must depict some type of coherent analysis) That’s all the instruction you have. Nicest plot wins a prize!


Download ppt "R Visualization with ggplot"

Similar presentations


Ads by Google