1 / 56

Introduction to Lattice Graphics

Introduction to Lattice Graphics. Richard Pugh 4 th December 2012. Agenda. Overview of Lattice Functions Creating basic graphics Panelled Graphics Grouped Data Multiple Variables Writing Panel Functions Summary. The Data We Will Use. Something relevant and sector independent

kovit
Download Presentation

Introduction to Lattice Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 http://data.london.gov.uk/datastore/package/tube-network-performance-data http://en.wikipedia.org/wiki/London_Underground

  4. Overview of Lattice Graphics

  5. 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 DeepayanSarkar, Fred Hutchinson Cancer Research Center

  6. List of Lattice Graphic Functions

  7. Key Function Arguments

  8. Creating Basic Graphics

  9. Panelled Graphics

  10. 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

  11. 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

  12. 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

  13. Grouped Data

  14. 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

  15. Take care!

  16. 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

  17. Multiple Variables

  18. 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

  19. Writing Panel Functions

  20. 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 …

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

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

More Related