Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Lattice Graphics Richard Pugh 4th December 2012.

Similar presentations


Presentation on theme: "Introduction to Lattice Graphics Richard Pugh 4th December 2012."— Presentation transcript:

1 Introduction to Lattice Graphics Richard Pugh 4th December 2012

2 Agenda Overview of Lattice Functions Creating basic graphics
Panelled Graphics Grouped Data Multiple Variables Writing Panel Functions Summary

3 The Data We Will Use Something relevant and sector independent London Tube Performance Data from the TFL website Excess Travel Hours by Line

4

5 Overview of Lattice Graphics

6 Overview of Lattice Graphics
One of the graphic systems of R (others include “Traditional” and “GGPlot”) An implementation of the S+ “Trellis” Graphics Written by Deepayan Sarkar, Fred Hutchinson Cancer Research Center

7 List of Lattice Graphic Functions
Description Graph Type xyplot Scatter plot Bivariate histogram Univariate histogram Univariate densityplot Univariate density line plot barchart Bar chart bwplot Box and whisker plot qq Normal QQ plot dotplot Label dot plot cloud 3D scatter plot 3D wireframe 3D surface plot splom Scatter matrix plot Data Frame parallel Multivariate parallel plot

8 Key Function Arguments
Description x Plot definition, typically as a formula data The data frame used for the graphic subset Any subsets to be applied to the data panel Function used to draw data in each “panel” groups Grouping variable for the plot Type of graph Formula Y axis X axis Z axis Univariate ~ Y Y - Bivariate Y ~ X X 3D Z ~ X*Y Z Data Frame ~ Data Data

9 Creating Basic Graphics

10

11

12

13

14

15

16 Panelled Graphics

17 Specifying Panels We can use the vertical pipe symbol “|” in order to specify “panels” to be plotted This allows us to create the graphics “by” one or more variables

18

19

20

21

22 Panel Variables During the plot creation, lattice builds a plot data frame containing the variables to plot By this time, any categorical “by” variables need to be factors So, either change them to characters or factors beforehand

23

24

25 Panel Ordering! If you have a factor variable, the ordering of the panels is in “graph” and not “table” order (!!) We can resolve using as.table = TRUE Note that the converting of characters to factors uses alphabetical ordering

26

27

28

29 Grouped Data

30 Grouped Data We can specify groupings within our data in order to plot these groupings separately By default, lattice will vary styling of the groups specified The key argument is the “groups” argument

31 Take care!

32

33 Controlling Styles Best done via the underlying lattice style templates Use of par.settings argument which takes a list of styles We usually use a basic template and change elements of it The show.settings function lets you see the current (or adapted) styles

34

35

36

37

38 Multiple Variables

39 Multiple Variables We can specify one or more X or Y axis variable in our lattice formula This can overwrite the “groups” input The “outer” argument controls how the multiple X/Y variables should be plotted

40

41

42

43

44

45 Writing Panel Functions

46 Panel Functions For each lattice graph, R performs the following actions: Partitions the data Draws the graph “outline” (i.e. the “panels”) Passes the data for each panel into the “panel” function We can overwrite this panel function and supply our own …

47 Panel Functions The default “panel” function for a lattice function is “panel.NameOfFunction” Let’s look at panel.xyplot …

48 Arguments for styling Jitter & other less used bits Let’s write our own panel function …….

49

50

51

52 Now what? Now we can insert other functions into a panel function which will then impact each individual plot panel We can call: Lattice “low level functions” (lpoints, ltext, llines, lpolygon etc) Existing “panel.” functions that exist for this purpose

53

54

55 Summary

56 Summary This was just a quick overview of lattice graphics
I hope it was useful For more info, look in the Lattice book, find examples online or contact Mango …


Download ppt "Introduction to Lattice Graphics Richard Pugh 4th December 2012."

Similar presentations


Ads by Google