SlideShare a Scribd company logo
1 of 46
Download to read offline
Visualisation in R
                       Hadley Wickham
            Assistant Professor / Dobelman Family Junior Chair
                 Department of Statistics / Rice University



July 2010
Sunday, 25 July 2010
HE LL O
                        my name is




                       Hadley
Sunday, 25 July 2010
http://had.co.nz/
                        vanderbilt-vis


Sunday, 25 July 2010
1. Preview of today
                2. About ggplot2
                3. More resources
                4. Diving in




Sunday, 25 July 2010
Fuel economy
                       Basic graphics


Sunday, 25 July 2010
●




                                          ●

                             40


                                      ●
                                      ●

                             35       ●
                                      ●
                                  ●   ●
                                  ●                       ●
                                              ●       ●●

                             30       ●       ●       ●
                                  ●   ●       ●   ●   ●●                              ●
                       hwy




                                              ●           ●                   ●       ●        ●
                                              ●   ●   ●●                  ●   ●       ●        ●
                                      ●       ●   ●   ●●          ●   ●●              ●●       ●    ●                                    ●               ●

                             25       ●                   ●       ●   ●●              ●        ●                                ●                        ●
                                                      ●●      ●●      ●       ●                     ●                                                            ●
                                                          ●       ●                            ●    ●   ●       ●                        ●
                                                              ●       ●       ●                ●                ●
                                                                                               ●                ●

                             20                               ●                                     ●                           ●●
                                                                                  ●        ●        ●           ●●              ●
                                                                                           ●        ●   ●   ●                       ●   ●●
                                                                              ●●                   ●●   ●       ●●      ●   ●       ●    ●       ●           ●
                                                                                                                ●●          ●       ●

                             15                                                                     ●           ●●          ●●●          ●   ●
                                                                                                                                ●                    ●


                                                                                                                    ●



                                              2                       3                             4                   5                        6               7
                                                                                                   displ
Sunday, 25 July 2010
●




                                          ●

                             40


                                      ●
                                      ●

                             35       ●
                                      ●
                                  ● ●                                                                                                              class
                                  ●                   ●
                                              ●   ●●
                                                                                                                                                    ●   2seater
                             30       ● ●         ●                                                                                                 ●   compact
                                  ● ● ● ● ●●                                    ●
                                                                                                                                                    ●   midsize
                       hwy




                                              ●       ●                 ● ●             ●
                                              ● ● ●●                  ● ● ●             ●                                                           ●   minivan
                                      ● ● ● ●●                ● ●●              ●● ● ●                                   ●             ●

                             25       ●               ●       ● ●●              ●       ●                         ●                    ●            ●   pickup
                                                  ●● ●● ●               ●                    ●                                                 ●
                                                      ●       ●                         ● ● ●        ●                   ●
                                                                                                                                                    ●   subcompact
                                                          ●       ●     ●               ●            ●                                              ●   suv
                                                                                        ●            ●

                             20                           ●                                  ●                    ●●
                                                                            ●       ●        ●       ●●           ●
                                                                                    ●        ● ● ●                    ● ●●
                                                                        ●●                  ●● ●     ●●      ● ● ●       ●     ●           ●
                                                                                                     ●●          ● ●

                             15                                                              ●       ●●          ●●●     ● ●
                                                                                                                  ●                ●


                                                                                                         ●



                                          2                       3                         4                5               6                 7
                                                                                        displ
Sunday, 25 July 2010
Diamond prices
                   Displaying large data


Sunday, 25 July 2010
4000




         3000
 count




         2000




         1000




            0

                       56   58   60    62     64   66   68   70
                                      depth
Sunday, 25 July 2010
●   ●   ●
                                             ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●   ●
                                     ●
                                     ●   ●
                                         ●   ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●     ●
                             ●       ●   ●   ●
                                             ●   ●   ●   ●   ●    ●
                                                                  ●   ●   ●
                               ●     ●   ●
                                         ●   ●   ●
                                                 ●   ●   ●   ●    ●   ●
                                     ●   ●   ●       ●   ●   ●    ●
                             ● ●     ●
                                     ●   ●
                                         ●
                                         ●
                                             ●
                                             ●
                                                 ●
                                                 ●
                                                 ●   ●
                                                     ●
                                                     ●
                                                         ●
                                                         ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●
                                                                  ●
                                                                      ●
                                                                      ●   ● ●
                                     ●   ●   ●   ●
                                                 ●   ●
                                                     ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●   ●
                               ●     ●   ●
                                         ●   ●
                                             ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●   ●    ●   ●   ●
                                     ●   ●
                                         ●   ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●
                                                                  ●   ●   ●
                               ●     ●
                                     ●   ●
                                         ●   ●   ●
                                                 ●   ●   ●
                                                         ●   ●
                                                             ●    ●   ●   ●
                                     ●
                                     ●   ●   ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●
                                                                      ●   ● ●
                                     ●   ●   ●   ●   ●   ●   ●
                                                             ●    ●
                                                                  ●   ●           ●
                                ●    ●   ●
                                         ●
                                         ●   ●
                                             ●   ●
                                                 ●   ●   ●   ●    ●   ●     ●
                                                                            ●     ●
                                     ●   ●   ●
                                             ●   ●
                                                 ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●   ●
                                ●
                                ●    ●   ●   ●   ●   ●   ●
                                                         ●   ●    ●   ●
                                                                      ●   ● ●
                                ●    ●   ●
                                         ●   ●
                                             ●   ●   ●
                                                     ●   ●
                                                         ●
                                                         ●   ●
                                                             ●    ●   ●   ●
                            ●   ●
                              ● ●    ●   ●   ●   ●
                                                 ●   ●
                                                     ●   ●   ●
                                                             ●    ●   ●
                                ●    ●   ●   ●
                                             ●
                                             ●   ●
                                                 ●   ●   ●   ●    ●   ●           ●
                                ●    ●
                                     ●   ●
                                         ●   ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●           ●●
                                                                                  ●
                                ●    ●
                                     ●   ●   ●   ●   ●   ●   ●
                                                             ●    ●   ●
                                ●    ●   ●
                                         ●
                                         ●   ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●   ●
                                                             ●    ●
                                                                  ●   ●
                                                                      ●
                                     ●   ●   ●       ●
                                                     ●   ●   ●            ● ●
         15000                  ●
                                ●
                                     ●
                                     ●
                                     ●
                                         ●
                                         ●
                                         ●
                                         ●
                                             ●
                                             ●
                                             ●
                                                 ●
                                                 ●
                                                 ●
                                                 ●
                                                     ●
                                                     ●
                                                     ●
                                                         ●
                                                         ●
                                                         ●
                                                         ●
                                                             ●
                                                             ●
                                                             ●
                                                                  ●
                                                                  ●
                                                                  ●
                                                                      ●
                                                                      ●
                                                                      ●   ●
                                                                          ●
                                                                            ●         ●
                                                                                      ●
                                     ●   ●
                                         ●   ●
                                             ●   ●   ●   ●   ●    ●
                                                                  ●   ●   ●
                              ●      ●
                                     ●   ●
                                         ●   ●
                                             ●
                                             ●   ●
                                                 ●   ●
                                                     ●   ●
                                                         ●        ●   ●
                                     ●
                                     ●   ●   ●   ●   ●   ●        ●
                                                                  ●
                                                                  ●   ●           ●
                                     ●
                                     ●   ●   ●   ●
                                                 ●   ●            ●
                                     ●   ●
                                         ●
                                         ●   ●
                                             ●   ●
                                                 ●   ●
                                                     ●            ●
                                                                  ●       ●
                                 ●   ●
                                     ●   ●   ●   ●   ●            ●   ●   ●
                                 ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●   ●
                                                 ●                ●
                                                                  ●   ●
                                                                      ●
                                                                      ●   ●       ●●●
                                 ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●   ●
                                                 ●                ●
                                                                  ●   ●           ●
                                 ●   ●
                                     ●   ●   ●   ●
                                                 ●                ●
                                                                  ●   ●       ●
                                     ●
                                     ●   ●
                                         ●   ●   ●
                                                 ●                ●
                                                                  ●   ●   ●         ●
                                         ●   ●   ●                ●
                                                                  ●   ●
                                                                      ●   ●
                                 ●
                                     ●
                                     ●
                                     ●
                                         ●
                                         ●   ●
                                             ●
                                             ●
                                                 ●
                                                 ●
                                                 ●                ●
                                                                  ●   ●
                                                                      ●   ●       ●●●     ●
                                     ●
                                     ●   ●
                                         ●   ●
                                             ●   ●
                                                 ●                ●
                                                                  ●   ●
                                                                      ●   ●
                                                                          ●
                                     ●   ●   ●
                                             ●   ●                ●
                                                                  ●   ●   ●   ●           ●
                                     ●
                                     ●   ●
                                         ●   ●
                                             ●
                                             ●   ●
                                                 ●                    ●
                                     ●   ●   ●
                                             ●   ●                    ●   ●           ●
                                 ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●                        ●   ●   ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●                        ●
                                                                      ●   ●   ●   ●
                                 ●
                                 ●   ●   ●   ●                            ●   ●
                                     ●   ●   ●                            ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●                                ●
                                                                              ●   ●● ●        ●
                                     ●
                                     ●   ●   ●                            ●   ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●                                ●   ●
                                 ●
                                 ●   ●   ●   ●
                                             ●                            ●         ● ●
                                 ●
                                 ●   ●
                                     ●   ●
                                         ●   ●
                                             ●                            ●
                                 ●   ●   ●
                                         ●
                                         ●   ●
                                             ●                                      ●
         10000                   ●
                                 ●
                                     ●
                                     ●
                                     ●
                                         ●
                                         ●
                                         ●
                                             ●                                    ●
 price




                                 ●   ●
                                     ●   ●
                                         ●
                                 ●
                                 ●   ●   ●                                            ●
                                 ●   ●
                                     ●   ●
                                         ●
                                 ●   ●
                                     ●   ●
                                         ●
                                     ●
                                     ●   ●
                                         ●                                            ●
                                     ●
                                     ●   ●
                                     ●
                                     ●
                                     ●
                                     ●




         5000




                       50                                    60                               70   80   90
                                                                                   table
Sunday, 25 July 2010
15000



                                                   count
                                                       1000
                                                       2000
         10000                                         3000
 price




                                                       4000
                                                       5000
                                                       6000
                                                       7000

         5000




                       1   2           3   4   5
                               carat
Sunday, 25 July 2010
US baby names
                        US baby names

                       Data manipulation and
                          transformation


Sunday, 25 July 2010
6.4




              6.2




              6.0
 avg_length




                                                                     sex
                                                                           boy
                                                                           girl
              5.8




              5.6




              5.4

                    1880   1900   1920   1940   1960   1980   2000
                                         year
Sunday, 25 July 2010
0.95




        0.90




        0.85

                                                                  sex
 prop




                                                                        boy
        0.80                                                            girl




        0.75




        0.70




                 1880   1900   1920   1940   1960   1980   2000
                                      year
Sunday, 25 July 2010
Polishing your plots



Sunday, 25 July 2010
1. Scales: used to override default
                       perceptual mappings, and tune
                       parameters of axes and legends.

                2. Themes: control presentation of
                       non-data elements.

                3. Saving your work: to include in
                   reports, presentations, etc.



Sunday, 25 July 2010
Sunday, 25 July 2010
ggplot2



Sunday, 25 July 2010
About ggplot2
                       Graphical grammar (domain specific
                       language), based on “The Grammar of
                       Graphics” by Leland Wilkinson.
                       Specify what you want, not how to create it.
                       Many fiddly details taken care of.
                       “Instead of spending time making your graph
                       look pretty, you can focus on creating a graph
                       that bests reveals the messages in your data.”


Sunday, 25 July 2010
Useful resources
                       http://had.co.nz/ggplot2
                       http://had.co.nz/ggplot2/book
                       http://groups.google.com/group/ggplot2
                       http://learnr.wordpress.com
                       http://ggplot2.wik.is



Sunday, 25 July 2010
Learning a new
                       language is hard!
Sunday, 25 July 2010
Scatterplot basics
                install.packages("ggplot2")
                library(ggplot2)

                ?mpg
                head(mpg)
                str(mpg)
                summary(mpg)

                qplot(displ, hwy, data = mpg)



Sunday, 25 July 2010
Scatterplot basics
                install.packages("ggplot2")
                library(ggplot2)

                ?mpg
                head(mpg)
                                    In ggplot2, we
                str(mpg)           always explicitly
                summary(mpg)       specify the data

                qplot(displ, hwy, data = mpg)



Sunday, 25 July 2010
●




                                          ●

                             40


                                      ●
                                      ●

                             35       ●
                                      ●
                                  ●   ●
                                  ●                       ●
                                              ●       ●●

                             30       ●       ●       ●
                                  ●   ●       ●   ●   ●●                              ●
                       hwy




                                              ●           ●                   ●       ●        ●
                                              ●   ●   ●●                  ●   ●       ●        ●
                                      ●       ●   ●   ●●          ●   ●●              ●●       ●    ●                                    ●               ●

                             25       ●                   ●       ●   ●●              ●        ●                                ●                        ●
                                                      ●●      ●●      ●       ●                     ●                                                            ●
                                                          ●       ●                            ●    ●   ●       ●                        ●
                                                              ●       ●       ●                ●                ●
                                                                                               ●                ●

                             20                               ●                                     ●                           ●●
                                                                                  ●        ●        ●           ●●              ●
                                                                                           ●        ●   ●   ●                       ●   ●●
                                                                              ●●                   ●●   ●       ●●      ●   ●       ●    ●       ●           ●
                                                                                                                ●●          ●       ●

                             15                                                                     ●           ●●          ●●●          ●   ●
                                                                                                                                ●                    ●


                                                                                                                    ●



                                              2                       3                             4                   5                        6               7
qplot(displ, hwy, data = mpg)
                          displ
Sunday, 25 July 2010
Additional variables

                       Can display additional variables with
                       aesthetics (like shape, colour, size) or
                       facetting (small multiples displaying
                       different subsets)




Sunday, 25 July 2010
●




                                          ●

                             40


                                      ●
                                      ●

                             35       ●
                                      ●
                                  ● ●                                                                                                              class
                                  ●                   ●
                                              ●   ●●
                                                                                                                                                    ●   2seater
                             30       ● ●         ●                                                                                                 ●   compact
                                  ● ● ● ● ●●                                    ●
                                                                                                                                                    ●   midsize
                       hwy




                                              ●       ●                 ● ●             ●
                                              ● ● ●●                  ● ● ●             ●                                                           ●   minivan
                                      ● ● ● ●●                ● ●●              ●● ● ●                                   ●             ●

                             25       ●               ●       ● ●●              ●       ●                         ●                    ●            ●   pickup
                                                  ●● ●● ●               ●                    ●                                                 ●
                                                      ●       ●                         ● ● ●        ●                   ●
                                                                                                                                                    ●   subcompact
                                                          ●       ●     ●               ●            ●                                              ●   suv
                                                                                        ●            ●

                             20                           ●                                  ●                    ●●
                                                                            ●       ●        ●       ●●           ●
                                                                                    ●        ● ● ●                    ● ●●
                                                                        ●●                  ●● ●     ●●      ● ● ●       ●     ●           ●
                                                                                                     ●●          ● ●

                             15                                                              ●       ●●          ●●●     ● ●
                                                                                                                  ●                ●


                                                                                                         ●



                                          2                       3                         4                5               6                 7
qplot(displ, hwy, colour = class, data = mpg)
                      displ
Sunday, 25 July 2010
●




                                          ●

                             40


                                      ●
                                      ●

                             35       ●
                                      ●
                                  ● ●                                                                                                              class
                                  ●                   ●
                                              ●   ●●
                                                                                                                                                    ●   2seater
                             30       ● ●         ●                                                                                                 ●   compact
                                  ● ● ● ● ●●                                    ●
                                                                                                                                                    ●   midsize
                       hwy




                                              ●       ●                 ● ●             ●
                                              ● ● ●●                  ● ● ●             ●                                                           ●   minivan
                                      ● ● ● ●●                ● ●●              ●● ● ●                                   ●             ●

                             25       ●               ●       ● ●●              ●       ●                         ●                    ●            ●   pickup
                                                  ●● ●● ●               ●                    ●                                                 ●
                                                      ●       ●                         ● ● ●        ●                   ●
                                                                                                                                                    ●   subcompact
                                                          ●       ●     ●               ●            ●                                              ●   suv
                                                                                        ●            ●

                             20                           ●                                  ●                    ●●
                                                                            ●       ●        ●       ●●           ●
                                                                                    ●        ● ● ●                    ● ●●                       Legend chosen and
                                                                                                                                               displayed automatically.
                                                                        ●●                  ●● ●     ●●      ● ● ●       ●     ●           ●
                                                                                                     ●●          ● ●

                             15                                                              ●       ●●          ●●●     ● ●
                                                                                                                  ●                ●


                                                                                                         ●



                                          2                       3                         4                5               6                 7
qplot(displ, hwy, colour = class, data = mpg)
                      displ
Sunday, 25 July 2010
Your turn
                       Experiment with colour, size, and shape
                       aesthetics.
                       What’s the difference between discrete or
                       continuous variables?
                       What happens when you combine
                       multiple aesthetics?



Sunday, 25 July 2010
Discrete        Continuous

                        Rainbow of       Gradient from
          Colour
                         colours          red to blue

                                         Linear mapping
                        Discrete size
               Size                      between radius
                           steps
                                            and value

                       Different shape
           Shape                          Doesn’t work
                           for each

Sunday, 25 July 2010
Faceting

                       Small multiples displaying different
                       subsets of the data.
                       Useful for exploring conditional
                       relationships. Useful for large data.




Sunday, 25 July 2010
Your turn
                       qplot(displ, hwy, data = mpg) +
                       facet_grid(. ~ cyl)
                       qplot(displ, hwy, data = mpg) +
                       facet_grid(drv ~ .)
                       qplot(displ, hwy, data = mpg) +
                       facet_grid(drv ~ cyl)
                       qplot(displ, hwy, data = mpg) +
                       facet_wrap(~ class)


Sunday, 25 July 2010
Summary

                       facet_grid(): 2d grid, rows ~ cols, . for
                       no split
                       facet_wrap(): 1d ribbon wrapped into 2d
                       Scales argument controls whether
                       position scales are fixed or free.



Sunday, 25 July 2010
What’s the                                                                               ●   ●




                             40   problem with                                                                    ●




                                  this plot?                                                     ●   ●
                                                                                                              ●


                             35                                                                           ●
                                                                                                          ●
                                                                                                 ●            ●
                                                                                             ●   ●   ●
                                                                                ●    ●   ●   ●

                             30                                                      ●   ●       ●
                                                                        ●   ●   ●    ●   ●   ●
                       hwy




                                                                        ●   ●   ●
                                                                    ●   ●   ●   ●    ●
                                                                ●   ●   ●   ●   ●    ●

                             25                            ●    ●   ●   ●   ●   ●
                                                           ●    ●   ●   ●
                                                           ●    ●       ●
                                                           ●    ●   ●
                                                           ●

                             20                        ●   ●    ●
                                                   ●   ●   ●
                                               ●   ●   ●   ●
                                           ●   ●   ●   ●   ●
                                           ●   ●   ●

                             15            ●
                                           ●


                                  ●



                                      10                   15                   20                   25               30       35
qplot(cty, hwy, data = mpg)
                       cty
Sunday, 25 July 2010
●   ●




                                                                                                               ●

                             40


                                                                                                           ●
                                                                                                 ●
                                                                                             ●
                                                                                                      ●●
                             35
                                                                                                       ●
                                                                                            ●              ●
                                                                                        ●    ● ●
                                                                                              ●
                                                                            ●      ●
                                                                                  ●● ● ●
                                                                                    ●
                                                                                            ●
                             30                                                  ●
                                                                                    ●
                                                                                      ●
                                                                     ●
                                                                     ●●          ●● ● ●
                                                                                  ●●
                                                                                   ●
                                                                                  ●●
                                                                           ● ● ●● ●●    ●
                                                                      ●     ●● ●
                       hwy




                                                                         ●
                                                                         ●●     ●
                                                                  ● ●● ●● ●    ● ●
                                                                           ● ●  ● ●
                                                                       ● ● ●
                                                                ● ● ●● ●● ●
                                                                       ● ●
                                                                       ● ●         ●
                                                             ●● ●     ●● ●
                                                                ●● ● ● ●
                                                                       ● ●      ●
                                                        ● ●         ● ●● ●●
                                                                          ●
                             25                             ● ●● ● ●     ●    ●
                                                         ●      ● ●
                                                               ● ●● ●
                                                                   ●
                                                         ●        ●
                                                                  ●● ●
                                                           ●● ●
                                                              ●
                                                          ● ●
                                                           ●        ●●
                                                           ● ●
                                                            ●
                                                               ● ●
                                                         ●
                                                           ●
                                                              ●
                             20                     ●● ● ● ●●
                                                     ●
                                                     ●    ● ●
                                                  ●● ●    ●●
                                                           ●
                                               ● ●● ●  ● ●
                                                        ●
                                            ● ● ●● ● ●
                                            ● ●
                                                  ●
                                         ●   ● ● ● ●● ● ●
                                         ●
                                        ●●      ●●●●●● ●
                                                ●
                                                ●●     ●
                                         ●      ● ● ●●●
                                                   ●
                                         ● ● ●●● ●
                                          ●
                             15         ●●
                                        ●●
                                        ●●
                                         ●
                                         ●
                                        ●
                                         ●

                                  ●
                                  ●●
                                  ●●



                                       10               15                 20                    25                30       35
qplot(cty, hwy, data = mpg, geom = "jitter")
                       cty
Sunday, 25 July 2010
●   ●




                                                                                                               ●

                             40


                                                                                                           ●
                                                                                                 ●
                                                                                             ●
                                                                                                      ●●
                             35
                                                                                                       ●
                                                                                            ●              ●
                                                                                        ●    ● ●
                                                                                              ●
                                                                            ●      ●
                                                                                  ●● ● ●
                                                                                    ●
                                                                                            ●
                             30                                                  ●
                                                                                    ●
                                                                                      ●
                                                                     ●
                                                                     ●●          ●● ● ●
                                                                                  ●●
                                                                                   ●
                                                                                  ●●
                                                                           ● ● ●● ●●    ●
                                                                      ●     ●● ●
                       hwy




                                                                         ●
                                                                         ●●     ●
                                                                  ● ●● ●● ●    ● ●
                                                                           ● ●  ● ●
                                                                       ● ● ●
                                                                ● ● ●● ●● ●
                                                                       ● ●
                                                                       ● ●         ●
                                                             ●● ●     ●● ●
                                                                ●● ● ● ●
                                                                       ● ●      ●
                                                        ● ●         ● ●● ●●
                                                                          ●
                             25                             ● ●● ● ●     ●    ●
                                                         ●      ● ●
                                                               ● ●● ●
                                                                   ●
                                                         ●        ●
                                                                  ●● ●
                                                           ●● ●
                                                              ●
                                                          ● ●
                                                           ●        ●●
                                                           ● ●
                                                            ●
                                                               ● ●
                                                         ●
                                                           ●
                                                              ●
                             20                     ●● ● ● ●●
                                                     ●
                                                     ●    ● ●
                                                  ●● ●    ●●
                                                           ●
                                               ● ●● ●  ● ●
                                                        ●
                                            ● ● ●● ● ●
                                            ● ●
                                                  ●
                                         ●   ● ● ● ●● ● ●
                                         ●
                                        ●●      ●●●●●● ●
                                                ●
                                                ●●     ●
                                         ●      ● ● ●●●
                                                   ●
                                         ● ● ●●● ●
                                          ●
                             15         ●●
                                        ●●
                                        ●●
                                         ●
                                         ●
                                        ●
                                         ●

                                  ●
                                  ●●
                                                                                                       geom controls
                                  ●●
                                                                                                       “type” of plot
                                       10               15                 20                    25                30       35
qplot(cty, hwy, data = mpg, geom = "jitter")
                       cty
Sunday, 25 July 2010
●                                       ●




                                                                       ●

       40


                               ●
                                                                       ●

       35                      ●
                                                                       ●
                               ●                                       ●
                                         ●                             ●
                               ●         ●

       30                      ●         ●
                               ●         ●                             ●
 hwy




                               ●         ●                             ●
                               ●         ●                             ●         ●
                       ●       ●         ●                             ●         ●

       25              ●       ●         ●                             ●         ●
                       ●       ●         ●         ●                   ●         ●
                       ●       ●         ●         ●                   ●         ●
                                                   ●        ●          ●         ●
                                                   ●                   ●

       20                                                   ●          ●         ●
                                                            ●                    ●
                                                            ●                    ●
                                                   ●        ●                    ●
                                                            ●                    ●

       15                                                   ●                    ●
                                                                                 ●


                                                            ●                    ●



                  2seater   compact   midsize   minivan   pickup   subcompact   suv
qplot(class, hwy, data = mpg)
                          class
Sunday, 25 July 2010
How could        ●                                       ●




              we improve
                                                                       ●

       40


              this plot?       ●
                                                                       ●

       35                      ●
                                                                       ●



               Brainstorm      ●


                               ●
                                         ●
                                         ●
                                                                       ●
                                                                       ●


       30
               for 1 minute.
                               ●         ●
                               ●         ●                             ●
 hwy




                               ●         ●                             ●
                               ●         ●                             ●         ●
                       ●       ●         ●                             ●         ●

       25              ●       ●         ●                             ●         ●
                       ●       ●         ●         ●                   ●         ●
                       ●       ●         ●         ●                   ●         ●
                                                   ●        ●          ●         ●
                                                   ●                   ●

       20                                                   ●          ●         ●
                                                            ●                    ●
                                                            ●                    ●
                                                   ●        ●                    ●
                                                            ●                    ●

       15                                                   ●                    ●
                                                                                 ●


                                                            ●                    ●



                  2seater   compact   midsize   minivan   pickup   subcompact   suv
qplot(class, hwy, data = mpg)
                          class
Sunday, 25 July 2010
●           ●




                                                                             ●

       40


                                                                                         ●
                                                                             ●

       35                                                                                ●
                                                                             ●
                                                                             ●           ●
                                                                  ●          ●
                                                                  ●                      ●

       30                                                         ●                      ●
                                                                  ●          ●           ●
 hwy




                                                                  ●          ●           ●
                             ●                                    ●          ●           ●
                             ●                      ●             ●          ●           ●

       25                    ●                      ●             ●          ●           ●
                             ●       ●              ●             ●          ●           ●
                             ●       ●              ●             ●          ●           ●
                       ●     ●       ●                                       ●
                                     ●                                       ●

       20              ●     ●                                               ●
                       ●     ●
                       ●     ●
                       ●     ●       ●
                       ●     ●

       15              ●     ●
                             ●


                       ●     ●



                   pickup   suv   minivan        2seater       midsize   subcompact   compact
                                         reorder(class, hwy)
Sunday, 25 July 2010
●           ●




                                                                        ●

       40


                                                                                    ●
                                                                        ●

       35                                                                           ●
                                                                        ●
                                                                        ●           ●
                                                             ●          ●
                                                             ●                      ●

       30                                                    ●                      ●
                                                             ●          ●           ●
 hwy




                                                             ●          ●           ●
                              ●                              ●          ●           ●
                              ●                    ●         ●          ●           ●

       25                     ●                    ●         ●          ●           ●
                              ●          ●         ●         ●          ●           ●
                              ●          ●         ●         ●          ●           ●
                       ●      ●          ●                              ●
                                         ●                              ●

       20              ●      ●                                         ●
                       ●      ●
                       ●      ●
                       ●      ●          ●
                       ●      ●

       15              ●      ●

                  Incredibly useful
                              ●



                     technique!
                       ●      ●



                   pickup    suv      minivan   2seater   midsize   subcompact   compact
qplot(reorder(class, hwy), hwy, data = mpg)
                      reorder(class, hwy)
Sunday, 25 July 2010
●                            ●




                                                                                                                                                                        ●

       40

                                                                                                                                                                                    ●

                                                                                                                                                            ●
                                                                                                                                           ●
                                                                                                                                                                                         ●    ●
       35
                                                                                                                                                   ●
                                                                                                                                                                                ●
                                                                                                                                                                    ●
                                                                                                                         ●                 ●       ●
                                                                                                                    ●                                           ●
                                                                                                                    ●                                                                   ●          ●
                                                                                                                     ●       ●                                                           ●
                                                                                                                                                                                ●
       30                                                                                                                     ●   ●                                                               ●

                                                                                                                          ● ● ●       ●●           ●       ●●                  ● ● ● ●
                                                                                                                                                                               ●
                                                                                                                                                                            ● ●●
                                                                                                                                                                             ●
                                                                                                                                           ●                        ●       ●●  ●
                                                                                                                              ●                                     ●             ●
                                                                                                                         ● ● ●                 ●
 hwy




                                                                                                                            ●                                               ●                ● ●
                                                                                                                                                                                             ● ●
                                                                    ●                                                ● ●     ●●                                         ●   ●
                                                        ●                                               ●             ●● ●
                                                                                                                      ●        ●
                                                                                                                                 ●         ●●              ●●                   ●        ●
                                                                                                            ●       ● ●
                                                                                                                    ● ●
                                                                                                                    ●         ●●●          ● ●                                   ●        ●     ●●
                                                                                                                    ●                                               ●                          ●
                                                                                                                                                   ●                            ● ●
       25                                           ●       ●                                     ●                          ● ●●
                                                                                                                                                                                         ●●
                                                                                                                                                                                         ●
                                                                                                                                                                                               ●
                                                                                                                                                                                               ●
                                                ●                            ●                ●                                                    ●                 ●              ●    ●
                                                                                                                ●                              ●
                                                                                     ●●                              ●                                              ●
                                                                                                            ●                ●
                                                                ●                         ●                                                    ●                                               ●
                                                                         ●
                                   ●                    ●                                 ●                                                                     ●
                                                                                 ●        ●                                                                      ●
                                                                         ●
                                                                                                                                                       ●
                       ●       ●
       20                          ●
                                           ●     ●
                                               ● ●          ●●      ●                                                                                           ●
                    ●                                       ●●      ●●
                  ●●       ●                ●                       ●●
                                                  ●      ●
                                       ●      ●
                    ●                         ●● ● ●●●
                     ●     ●
                           ●    ●          ● ● ● ●●
                       ●  ●     ●          ●●● ●     ●     ●                     ●
                   ● ● ●
                    ●                          ●● ●     ●  ●
                   ●● ●        ●                       ● ●
                         ●
                  ●                           ● ●
       15         ● ●        ●               ● ●        ● ●
                                                 ●
                                                 ●


                   ●           ●   ●                 ●          ●




                       pickup                        suv                     minivan                  2seater            midsize           subcompact                           compact
qplot(reorder(class, hwy),reorder(class, hwy) = mpg, geom = "jitter")
                            hwy, data
Sunday, 25 July 2010
●           ●




                                                                        ●

       40


                                                                                    ●


       35                                                                           ●




       30
 hwy




                                 ●
                                 ●

       25                        ●
                                 ●
                                 ●
                         ●


       20


                                         ●


       15


                         ●       ●



                       pickup   suv   minivan   2seater   midsize   subcompact   compact
qplot(reorder(class, hwy), hwy, data hwy)mpg, geom = "boxplot")
                           reorder(class, =
Sunday, 25 July 2010
●
                                                                                                                                                       ●                            ●
                                                                                                                                                                                    ●




                                                                                                                                                       ●           ●

       40


                                                                                                                                                                                    ● ●
                                                                                                                                                   ● ●

       35                                                                                                                                                                  ●        ● ●
                                                                                                                                                       ●
                                                                                                                                                                                           ●
                                                                                                                                                                   ●
                                                                                                                                ●             ● ● ●
                                                                                                               ●                                                           ●                 ●
                                                                                                                       ●        ●●                                                       ●
       30                                                                                                      ●           ●    ●                                              ●
                                                                                                                                                                              ●●
                                                                                                                                                                                        ●●
                                                                                                                                ●
                                                                                                                               ● ●                                 ●                      ●●
                                                                                                                                          ●   ●●●                           ●● ●●       ● ●●
                                                                                                                                   ●
                                                                                                                       ●       ●               ●                           ●
 hwy




                                                                                                                                ●
                                                                                                                                ●                              ●
                                                                                                               ●                 ●             ●                                    ●● ●●
                                                         ● ●                                                                                                               ●           ●
                                                                                                                   ●     ●            ●                                                 ●
                                                 ●                                                             ●        ●
                                                                                                                        ● ●          ●    ●   ●●●                  ●              ●●
                                                         ●                                             ●               ●●            ●
                                                                                                                                    ●●                                        ●      ●●
                                                                                                                                                                                      ●
                                                                                               ●                   ●    ●
                                                                                                                        ●           ●       ●   ●●                              ●
                                                                                                           ●
       25                                    ●           ●         ●                                               ●                ●                                        ● ●● ●
                                                                                                                                     ●
                                                                                                                                     ●                             ●       ●            ●
                                                         ●             ●                                   ●                              ●                ●
                                                                                                                                                           ●                         ●●
                                                                       ●       ●   ●                                   ●                                       ●
                                                               ●                                                                                                             ●
                                             ●           ●                                         ●               ●                                       ●
                                                                       ●                   ●
                           ●                                               ●
                           ●                             ●                 ●
                                                                                           ●                                                       ●           ●
                                                                                                                                                                       ●
                                                                                       ●
                                   ●          ●
       20          ●       ●               ●● ●
                                            ●        ●
                                                     ●                                                                                                 ●
                                                    ●● ● ●●
                  ●                ●● ●    ● ●       ●    ●
                                    ●
                                    ●          ●   ● ●  ●
                                                 ●
                                                 ●     ●
                              ●                 ●      ●                       ●
                  ● ●●
                     ●     ● ●●            ●●●●● ● ● ●
                                             ●
                                              ● ●● ● ● ● ●
                                                 ●                             ●
                       ● ● ●                           ●
                        ●                      ●
                   ●   ●
                       ●    ●
                          ●                  ●       ●
       15          ●     ●    ●              ●        ●●           ●
                                                     ●
                                                     ●

                                   ●             ●
                       ●       ●                         ●
                                                         ●
                                       ●



qplot(reorder(class,minivan
       pickup suv
                      hwy), 2seater data = subcompact
                                  hwy, midsize mpg,                                                                                                                            compact
  geom = c("jitter", "boxplot"))
                         reorder(class, hwy)
Sunday, 25 July 2010
Your turn

                       Read the help for reorder. Redraw the
                       previously plots with class ordered by
                       median hwy.
                       How would you put the jittered points on
                       top of the boxplots?




Sunday, 25 July 2010
Aside: coding strategy

                       At the end of each interactive session, you
                       want a summary of everything you did. Two
                       options:
                       1. Save everything you did with savehistory()
                       then remove the unimportant bits.
                       2. Build up the important bits as you go.
                       (this is how I work)


Sunday, 25 July 2010
Sunday, 25 July 2010
This work is licensed under the Creative
       Commons Attribution-Noncommercial 3.0 United
       States License. To view a copy of this license,
       visit http://creativecommons.org/licenses/by-nc/
       3.0/us/ or send a letter to Creative Commons,
       171 Second Street, Suite 300, San Francisco,
       California, 94105, USA.




Sunday, 25 July 2010

More Related Content

Similar to 1 basics

Over Visie, Missie En Strategie
Over Visie, Missie En StrategieOver Visie, Missie En Strategie
Over Visie, Missie En StrategieGuus Vos
 
About Vision, Mission And Strategy
About Vision, Mission And StrategyAbout Vision, Mission And Strategy
About Vision, Mission And StrategyGuus Vos
 
Los Angeles R users group - July 12 2011 - Part 1
Los Angeles R users group - July 12 2011 - Part 1Los Angeles R users group - July 12 2011 - Part 1
Los Angeles R users group - July 12 2011 - Part 1rusersla
 
Modul mulus bahagian c sjk (modul murid)
Modul mulus bahagian c sjk (modul murid)Modul mulus bahagian c sjk (modul murid)
Modul mulus bahagian c sjk (modul murid)Anparasu
 
Modul mulus bahagian c sjk (modul guru)
Modul mulus bahagian c sjk (modul guru)Modul mulus bahagian c sjk (modul guru)
Modul mulus bahagian c sjk (modul guru)Anparasu
 
Modul mulus bahagian c sk (modul murid)
Modul mulus bahagian c sk (modul murid)Modul mulus bahagian c sk (modul murid)
Modul mulus bahagian c sk (modul murid)Anparasu
 
Modul mulus bahagian c sk (modul guru)
Modul mulus bahagian c sk (modul guru)Modul mulus bahagian c sk (modul guru)
Modul mulus bahagian c sk (modul guru)Anparasu
 
正誤表 p39
正誤表 p39正誤表 p39
正誤表 p39zafiro555
 
Fairisle knitting
Fairisle knittingFairisle knitting
Fairisle knittingzafiro555
 
研修企画書11 12term voda-カヤック
研修企画書11 12term voda-カヤック研修企画書11 12term voda-カヤック
研修企画書11 12term voda-カヤックaiesecsfc_icx2011
 
How People Use Facebook -- And Why It Matters
How People Use Facebook -- And Why It MattersHow People Use Facebook -- And Why It Matters
How People Use Facebook -- And Why It MattersMat Morrison
 
研修企画書11-12term voda-カヤック
研修企画書11-12term voda-カヤック研修企画書11-12term voda-カヤック
研修企画書11-12term voda-カヤックaiesecsfc_icx2011
 
Barley environmental association - Plant & Animal Genome 2018
Barley environmental association - Plant & Animal Genome 2018Barley environmental association - Plant & Animal Genome 2018
Barley environmental association - Plant & Animal Genome 2018PeterMorrell4
 

Similar to 1 basics (20)

02 large
02 large02 large
02 large
 
13 Bivariate
13 Bivariate13 Bivariate
13 Bivariate
 
01 intro
01 intro01 intro
01 intro
 
Over Visie, Missie En Strategie
Over Visie, Missie En StrategieOver Visie, Missie En Strategie
Over Visie, Missie En Strategie
 
About Vision, Mission And Strategy
About Vision, Mission And StrategyAbout Vision, Mission And Strategy
About Vision, Mission And Strategy
 
Los Angeles R users group - July 12 2011 - Part 1
Los Angeles R users group - July 12 2011 - Part 1Los Angeles R users group - July 12 2011 - Part 1
Los Angeles R users group - July 12 2011 - Part 1
 
Modul mulus bahagian c sjk (modul murid)
Modul mulus bahagian c sjk (modul murid)Modul mulus bahagian c sjk (modul murid)
Modul mulus bahagian c sjk (modul murid)
 
Modul mulus bahagian c sjk (modul guru)
Modul mulus bahagian c sjk (modul guru)Modul mulus bahagian c sjk (modul guru)
Modul mulus bahagian c sjk (modul guru)
 
Modul mulus bahagian c sk (modul murid)
Modul mulus bahagian c sk (modul murid)Modul mulus bahagian c sk (modul murid)
Modul mulus bahagian c sk (modul murid)
 
Modul mulus bahagian c sk (modul guru)
Modul mulus bahagian c sk (modul guru)Modul mulus bahagian c sk (modul guru)
Modul mulus bahagian c sk (modul guru)
 
17 Sampling Dist
17 Sampling Dist17 Sampling Dist
17 Sampling Dist
 
21 Ml
21 Ml21 Ml
21 Ml
 
08 Continuous
08 Continuous08 Continuous
08 Continuous
 
08 Continuous
08 Continuous08 Continuous
08 Continuous
 
正誤表 p39
正誤表 p39正誤表 p39
正誤表 p39
 
Fairisle knitting
Fairisle knittingFairisle knitting
Fairisle knitting
 
研修企画書11 12term voda-カヤック
研修企画書11 12term voda-カヤック研修企画書11 12term voda-カヤック
研修企画書11 12term voda-カヤック
 
How People Use Facebook -- And Why It Matters
How People Use Facebook -- And Why It MattersHow People Use Facebook -- And Why It Matters
How People Use Facebook -- And Why It Matters
 
研修企画書11-12term voda-カヤック
研修企画書11-12term voda-カヤック研修企画書11-12term voda-カヤック
研修企画書11-12term voda-カヤック
 
Barley environmental association - Plant & Animal Genome 2018
Barley environmental association - Plant & Animal Genome 2018Barley environmental association - Plant & Animal Genome 2018
Barley environmental association - Plant & Animal Genome 2018
 

More from Ajay Ohri

Introduction to R ajay Ohri
Introduction to R ajay OhriIntroduction to R ajay Ohri
Introduction to R ajay OhriAjay Ohri
 
Introduction to R
Introduction to RIntroduction to R
Introduction to RAjay Ohri
 
Social Media and Fake News in the 2016 Election
Social Media and Fake News in the 2016 ElectionSocial Media and Fake News in the 2016 Election
Social Media and Fake News in the 2016 ElectionAjay Ohri
 
Download Python for R Users pdf for free
Download Python for R Users pdf for freeDownload Python for R Users pdf for free
Download Python for R Users pdf for freeAjay Ohri
 
Install spark on_windows10
Install spark on_windows10Install spark on_windows10
Install spark on_windows10Ajay Ohri
 
Ajay ohri Resume
Ajay ohri ResumeAjay ohri Resume
Ajay ohri ResumeAjay Ohri
 
Statistics for data scientists
Statistics for  data scientistsStatistics for  data scientists
Statistics for data scientistsAjay Ohri
 
National seminar on emergence of internet of things (io t) trends and challe...
National seminar on emergence of internet of things (io t)  trends and challe...National seminar on emergence of internet of things (io t)  trends and challe...
National seminar on emergence of internet of things (io t) trends and challe...Ajay Ohri
 
Tools and techniques for data science
Tools and techniques for data scienceTools and techniques for data science
Tools and techniques for data scienceAjay Ohri
 
How Big Data ,Cloud Computing ,Data Science can help business
How Big Data ,Cloud Computing ,Data Science can help businessHow Big Data ,Cloud Computing ,Data Science can help business
How Big Data ,Cloud Computing ,Data Science can help businessAjay Ohri
 
Training in Analytics and Data Science
Training in Analytics and Data ScienceTraining in Analytics and Data Science
Training in Analytics and Data ScienceAjay Ohri
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data ScientistsAjay Ohri
 
A Data Science Tutorial in Python
A Data Science Tutorial in PythonA Data Science Tutorial in Python
A Data Science Tutorial in PythonAjay Ohri
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen OomsAjay Ohri
 
Using R for Social Media and Sports Analytics
Using R for Social Media and Sports AnalyticsUsing R for Social Media and Sports Analytics
Using R for Social Media and Sports AnalyticsAjay Ohri
 
Kush stats alpha
Kush stats alpha Kush stats alpha
Kush stats alpha Ajay Ohri
 
Analyze this
Analyze thisAnalyze this
Analyze thisAjay Ohri
 

More from Ajay Ohri (20)

Introduction to R ajay Ohri
Introduction to R ajay OhriIntroduction to R ajay Ohri
Introduction to R ajay Ohri
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Social Media and Fake News in the 2016 Election
Social Media and Fake News in the 2016 ElectionSocial Media and Fake News in the 2016 Election
Social Media and Fake News in the 2016 Election
 
Pyspark
PysparkPyspark
Pyspark
 
Download Python for R Users pdf for free
Download Python for R Users pdf for freeDownload Python for R Users pdf for free
Download Python for R Users pdf for free
 
Install spark on_windows10
Install spark on_windows10Install spark on_windows10
Install spark on_windows10
 
Ajay ohri Resume
Ajay ohri ResumeAjay ohri Resume
Ajay ohri Resume
 
Statistics for data scientists
Statistics for  data scientistsStatistics for  data scientists
Statistics for data scientists
 
National seminar on emergence of internet of things (io t) trends and challe...
National seminar on emergence of internet of things (io t)  trends and challe...National seminar on emergence of internet of things (io t)  trends and challe...
National seminar on emergence of internet of things (io t) trends and challe...
 
Tools and techniques for data science
Tools and techniques for data scienceTools and techniques for data science
Tools and techniques for data science
 
How Big Data ,Cloud Computing ,Data Science can help business
How Big Data ,Cloud Computing ,Data Science can help businessHow Big Data ,Cloud Computing ,Data Science can help business
How Big Data ,Cloud Computing ,Data Science can help business
 
Training in Analytics and Data Science
Training in Analytics and Data ScienceTraining in Analytics and Data Science
Training in Analytics and Data Science
 
Tradecraft
Tradecraft   Tradecraft
Tradecraft
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
 
Craps
CrapsCraps
Craps
 
A Data Science Tutorial in Python
A Data Science Tutorial in PythonA Data Science Tutorial in Python
A Data Science Tutorial in Python
 
How does cryptography work? by Jeroen Ooms
How does cryptography work?  by Jeroen OomsHow does cryptography work?  by Jeroen Ooms
How does cryptography work? by Jeroen Ooms
 
Using R for Social Media and Sports Analytics
Using R for Social Media and Sports AnalyticsUsing R for Social Media and Sports Analytics
Using R for Social Media and Sports Analytics
 
Kush stats alpha
Kush stats alpha Kush stats alpha
Kush stats alpha
 
Analyze this
Analyze thisAnalyze this
Analyze this
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

1 basics

  • 1. Visualisation in R Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University July 2010 Sunday, 25 July 2010
  • 2. HE LL O my name is Hadley Sunday, 25 July 2010
  • 3. http://had.co.nz/ vanderbilt-vis Sunday, 25 July 2010
  • 4. 1. Preview of today 2. About ggplot2 3. More resources 4. Diving in Sunday, 25 July 2010
  • 5. Fuel economy Basic graphics Sunday, 25 July 2010
  • 6. ● 40 ● ● 35 ● ● ● ● ● ● ● ●● 30 ● ● ● ● ● ● ● ●● ● hwy ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● 25 ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ● ●● ● ● 15 ● ●● ●●● ● ● ● ● ● 2 3 4 5 6 7 displ Sunday, 25 July 2010
  • 7. ● 40 ● ● 35 ● ● ● ● class ● ● ● ●● ● 2seater 30 ● ● ● ● compact ● ● ● ● ●● ● ● midsize hwy ● ● ● ● ● ● ● ●● ● ● ● ● ● minivan ● ● ● ●● ● ●● ●● ● ● ● ● 25 ● ● ● ●● ● ● ● ● ● pickup ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● subcompact ● ● ● ● ● ● suv ● ● 20 ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ● ●● ● ● 15 ● ●● ●●● ● ● ● ● ● 2 3 4 5 6 7 displ Sunday, 25 July 2010
  • 8. Diamond prices Displaying large data Sunday, 25 July 2010
  • 9. 4000 3000 count 2000 1000 0 56 58 60 62 64 66 68 70 depth Sunday, 25 July 2010
  • 10. ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 15000 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 10000 ● ● ● ● ● ● ● ● ● ● price ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 5000 50 60 70 80 90 table Sunday, 25 July 2010
  • 11. 15000 count 1000 2000 10000 3000 price 4000 5000 6000 7000 5000 1 2 3 4 5 carat Sunday, 25 July 2010
  • 12. US baby names US baby names Data manipulation and transformation Sunday, 25 July 2010
  • 13. 6.4 6.2 6.0 avg_length sex boy girl 5.8 5.6 5.4 1880 1900 1920 1940 1960 1980 2000 year Sunday, 25 July 2010
  • 14. 0.95 0.90 0.85 sex prop boy 0.80 girl 0.75 0.70 1880 1900 1920 1940 1960 1980 2000 year Sunday, 25 July 2010
  • 16. 1. Scales: used to override default perceptual mappings, and tune parameters of axes and legends. 2. Themes: control presentation of non-data elements. 3. Saving your work: to include in reports, presentations, etc. Sunday, 25 July 2010
  • 19. About ggplot2 Graphical grammar (domain specific language), based on “The Grammar of Graphics” by Leland Wilkinson. Specify what you want, not how to create it. Many fiddly details taken care of. “Instead of spending time making your graph look pretty, you can focus on creating a graph that bests reveals the messages in your data.” Sunday, 25 July 2010
  • 20. Useful resources http://had.co.nz/ggplot2 http://had.co.nz/ggplot2/book http://groups.google.com/group/ggplot2 http://learnr.wordpress.com http://ggplot2.wik.is Sunday, 25 July 2010
  • 21. Learning a new language is hard! Sunday, 25 July 2010
  • 22. Scatterplot basics install.packages("ggplot2") library(ggplot2) ?mpg head(mpg) str(mpg) summary(mpg) qplot(displ, hwy, data = mpg) Sunday, 25 July 2010
  • 23. Scatterplot basics install.packages("ggplot2") library(ggplot2) ?mpg head(mpg) In ggplot2, we str(mpg) always explicitly summary(mpg) specify the data qplot(displ, hwy, data = mpg) Sunday, 25 July 2010
  • 24. ● 40 ● ● 35 ● ● ● ● ● ● ● ●● 30 ● ● ● ● ● ● ● ●● ● hwy ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●● ●● ● ● ● ● 25 ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ● ●● ● ● 15 ● ●● ●●● ● ● ● ● ● 2 3 4 5 6 7 qplot(displ, hwy, data = mpg) displ Sunday, 25 July 2010
  • 25. Additional variables Can display additional variables with aesthetics (like shape, colour, size) or facetting (small multiples displaying different subsets) Sunday, 25 July 2010
  • 26. ● 40 ● ● 35 ● ● ● ● class ● ● ● ●● ● 2seater 30 ● ● ● ● compact ● ● ● ● ●● ● ● midsize hwy ● ● ● ● ● ● ● ●● ● ● ● ● ● minivan ● ● ● ●● ● ●● ●● ● ● ● ● 25 ● ● ● ●● ● ● ● ● ● pickup ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● subcompact ● ● ● ● ● ● suv ● ● 20 ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●● ●● ● ●● ● ● ● ● ● ● ●● ● ● 15 ● ●● ●●● ● ● ● ● ● 2 3 4 5 6 7 qplot(displ, hwy, colour = class, data = mpg) displ Sunday, 25 July 2010
  • 27. ● 40 ● ● 35 ● ● ● ● class ● ● ● ●● ● 2seater 30 ● ● ● ● compact ● ● ● ● ●● ● ● midsize hwy ● ● ● ● ● ● ● ●● ● ● ● ● ● minivan ● ● ● ●● ● ●● ●● ● ● ● ● 25 ● ● ● ●● ● ● ● ● ● pickup ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● subcompact ● ● ● ● ● ● suv ● ● 20 ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● Legend chosen and displayed automatically. ●● ●● ● ●● ● ● ● ● ● ● ●● ● ● 15 ● ●● ●●● ● ● ● ● ● 2 3 4 5 6 7 qplot(displ, hwy, colour = class, data = mpg) displ Sunday, 25 July 2010
  • 28. Your turn Experiment with colour, size, and shape aesthetics. What’s the difference between discrete or continuous variables? What happens when you combine multiple aesthetics? Sunday, 25 July 2010
  • 29. Discrete Continuous Rainbow of Gradient from Colour colours red to blue Linear mapping Discrete size Size between radius steps and value Different shape Shape Doesn’t work for each Sunday, 25 July 2010
  • 30. Faceting Small multiples displaying different subsets of the data. Useful for exploring conditional relationships. Useful for large data. Sunday, 25 July 2010
  • 31. Your turn qplot(displ, hwy, data = mpg) + facet_grid(. ~ cyl) qplot(displ, hwy, data = mpg) + facet_grid(drv ~ .) qplot(displ, hwy, data = mpg) + facet_grid(drv ~ cyl) qplot(displ, hwy, data = mpg) + facet_wrap(~ class) Sunday, 25 July 2010
  • 32. Summary facet_grid(): 2d grid, rows ~ cols, . for no split facet_wrap(): 1d ribbon wrapped into 2d Scales argument controls whether position scales are fixed or free. Sunday, 25 July 2010
  • 33. What’s the ● ● 40 problem with ● this plot? ● ● ● 35 ● ● ● ● ● ● ● ● ● ● ● 30 ● ● ● ● ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ● ● ● ● ● 25 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● ● 10 15 20 25 30 35 qplot(cty, hwy, data = mpg) cty Sunday, 25 July 2010
  • 34. ● ● 40 ● ● ● ●● 35 ● ● ● ● ● ● ● ● ● ●● ● ● ● ● 30 ● ● ● ● ●● ●● ● ● ●● ● ●● ● ● ●● ●● ● ● ●● ● hwy ● ●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ●● ● 25 ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● 20 ●● ● ● ●● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●●●●●● ● ● ●● ● ● ● ● ●●● ● ● ● ●●● ● ● 15 ●● ●● ●● ● ● ● ● ● ●● ●● 10 15 20 25 30 35 qplot(cty, hwy, data = mpg, geom = "jitter") cty Sunday, 25 July 2010
  • 35. ● ● 40 ● ● ● ●● 35 ● ● ● ● ● ● ● ● ● ●● ● ● ● ● 30 ● ● ● ● ●● ●● ● ● ●● ● ●● ● ● ●● ●● ● ● ●● ● hwy ● ●● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ●● ●● ● 25 ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● 20 ●● ● ● ●● ● ● ● ● ●● ● ●● ● ● ●● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ●●●●●● ● ● ●● ● ● ● ● ●●● ● ● ● ●●● ● ● 15 ●● ●● ●● ● ● ● ● ● ●● geom controls ●● “type” of plot 10 15 20 25 30 35 qplot(cty, hwy, data = mpg, geom = "jitter") cty Sunday, 25 July 2010
  • 36. ● ● 40 ● ● 35 ● ● ● ● ● ● ● ● 30 ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ● ● ● 25 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● ● ● ● 2seater compact midsize minivan pickup subcompact suv qplot(class, hwy, data = mpg) class Sunday, 25 July 2010
  • 37. How could ● ● we improve ● 40 this plot? ● ● 35 ● ● Brainstorm ● ● ● ● ● ● 30 for 1 minute. ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ● ● ● 25 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● ● ● ● 2seater compact midsize minivan pickup subcompact suv qplot(class, hwy, data = mpg) class Sunday, 25 July 2010
  • 38. ● ● 40 ● ● 35 ● ● ● ● ● ● ● ● 30 ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ● ● ● 25 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● ● ● ● pickup suv minivan 2seater midsize subcompact compact reorder(class, hwy) Sunday, 25 July 2010
  • 39. ● ● 40 ● ● 35 ● ● ● ● ● ● ● ● 30 ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ● ● ● 25 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● Incredibly useful ● technique! ● ● pickup suv minivan 2seater midsize subcompact compact qplot(reorder(class, hwy), hwy, data = mpg) reorder(class, hwy) Sunday, 25 July 2010
  • 40. ● ● 40 ● ● ● ● ● 35 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 30 ● ● ● ● ● ● ●● ● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● hwy ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ● ● 25 ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ● ● ● ●● ● ● ● ●● ●● ●● ● ● ●● ● ● ● ● ● ●● ● ●●● ● ● ● ● ● ● ● ●● ● ● ● ●●● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● 15 ● ● ● ● ● ● ● ● ● ● ● ● ● ● pickup suv minivan 2seater midsize subcompact compact qplot(reorder(class, hwy),reorder(class, hwy) = mpg, geom = "jitter") hwy, data Sunday, 25 July 2010
  • 41. ● ● 40 ● 35 ● 30 hwy ● ● 25 ● ● ● ● 20 ● 15 ● ● pickup suv minivan 2seater midsize subcompact compact qplot(reorder(class, hwy), hwy, data hwy)mpg, geom = "boxplot") reorder(class, = Sunday, 25 July 2010
  • 42. ● ● ● ● ● 40 ● ● ● ● 35 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● 30 ● ● ● ● ●● ●● ● ● ● ● ●● ● ●●● ●● ●● ● ●● ● ● ● ● ● hwy ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ●● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ●● ● ● 25 ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ●● ● ● ● ● ● ●● ● ●● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ●● ●●●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 15 ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● qplot(reorder(class,minivan pickup suv hwy), 2seater data = subcompact hwy, midsize mpg, compact geom = c("jitter", "boxplot")) reorder(class, hwy) Sunday, 25 July 2010
  • 43. Your turn Read the help for reorder. Redraw the previously plots with class ordered by median hwy. How would you put the jittered points on top of the boxplots? Sunday, 25 July 2010
  • 44. Aside: coding strategy At the end of each interactive session, you want a summary of everything you did. Two options: 1. Save everything you did with savehistory() then remove the unimportant bits. 2. Build up the important bits as you go. (this is how I work) Sunday, 25 July 2010
  • 46. This work is licensed under the Creative Commons Attribution-Noncommercial 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/ 3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Sunday, 25 July 2010