SlideShare a Scribd company logo
Introduction to ggplot22
Paul Richards, ScHARR, The University of Sheffield
Thursday, February 26, 2015
Introduction
ggplot2 is a package written by Hadley Wickham
Powerful but easy to use functions for 2D graphics
Based on the “Grammar of Graphics” theory by Leland
Wilkinson
use install.packages() to install latest version
Concepts
ggplot2 works with data.frames
aesthetic = a feature we can see on the graphic (shape, size,
colour etc)
map from data to aestheics (i.e. different colour per group)
layer = geometric object + data/aesthetics + statistical
transformation
a graphic will also have scale(s) and a co-ordinate system
may also have facets - subsetting plot by some characteristic(s)
Quick note on “plot”
The “plot” function in base R is just a wrapper for lots of
methods
Behaviour depends on what object is supplied
Can require some manual tinkering to get it to work as required
Example, using the “iris” data, plot petal length vs sepal length
Different colour for each species
Point size varies by sepal width
Scatterplot with “plot”
with(iris, plot(Sepal.Length, Petal.Length,
col = Species, cex = Sepal.Width))
4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0
1234567
Sepal.Length
Petal.Length
Problems
Cannot specify dataset within function
No legend, have to add manually via legend() which is fiddly to
use
Arguments are a bit “dumb” - we need to rescale Sepal.Width
to get better point sizes
Need to use different functions to add new geometric objects,
e.g. regression lines
Qplot
qplot(Sepal.Length, Petal.Length, data = iris,
color = Species, size = Sepal.Width)
2
4
6
5 6 7 8
Sepal.Length
Petal.Length
Species
setosa
versicolor
virginica
Sepal.Width
2.0
2.5
3.0
3.5
4.0
Qplot()
Qplot is the nearest equivalent to plot() in ggplot2
For single layer plots this is easy enough to use
Use geom argument to change plot type
Boxplot example
qplot(Species, Sepal.Length, data = iris, geom="boxplot")
5
6
7
8
setosa versicolor virginica
Species
Sepal.Length
Violin example
qplot(Species, Sepal.Length, data = iris, geom="violin")
5
6
7
8
setosa versicolor virginica
Species
Sepal.Length
Histogram example
qplot(Sepal.Length, data = iris, fill = Species)
0
5
10
4 5 6 7 8
Sepal.Length
count
Species
setosa
versicolor
virginica
ggplot()
For multilayer plots or where more flexibility is required
ggplot() sets up the default data and aesthetic mappings
add layers using the “+” operator and appropriate functions
all aesthetic mappings are wrapped in aes() function
global changes (e.g. set all points to “red”) go outside
Iris scatterplot again
ggplot(data = iris, aes(x = Sepal.Length,
y = Petal.Length, color = Species)) +
geom_point(aes(size = Sepal.Width))
2
4
6
5 6 7 8
Sepal.Length
Petal.Length
Species
setosa
versicolor
virginica
Sepal.Width
2.0
2.5
3.0
3.5
4.0
Alternative
ggplot(data = iris, aes(x = Sepal.Length,
y = Petal.Length, color = Species)) +
geom_point(size = 5)
2
4
6
5 6 7 8
Sepal.Length
Petal.Length
Species
setosa
versicolor
virginica
Adding to plots
ggplots are objects so you can save them as you go
You can then add new layers etc to the saved object
gg1 <- ggplot(data = iris, aes(x = Sepal.Length,
y = Petal.Length, color = Species)) +
geom_point(aes(size = Sepal.Width))
gg2 <- gg1 + geom_smooth()
gg2
Iris plot with loess smoother
2
4
6
5 6 7 8
Sepal.Length
Petal.Length
Species
setosa
versicolor
virginica
Sepal.Width
2.0
2.5
3.0
3.5
4.0
Add contours
gg3 <- gg2 + geom_density2d()
gg3
Add contours
2
4
6
5 6 7 8
Sepal.Length
Petal.Length
Species
setosa
versicolor
virginica
Sepal.Width
2.0
2.5
3.0
3.5
4.0
Note on statistical transformations
The loess smoother and contours in the previous plot are not
part of data
In base plot we would have to calculate them first
In ggplot2 the stat_*() functions do such tranformations for us
Often the corresponding geom_*() function does this
automatically
For more flexibility, use the stat_*() function and specify the
geom you need
Histogram example using stat_bin
stat_bin performs a 1d “binning” transformation
i.e. a histogram transformation
ggplot(data = iris,
aes(x = Sepal.Length, fill = Species)) +
stat_bin(binwidth=1,position="dodge")
Histogram example using stat_bin
0
10
20
30
4 6 8
Sepal.Length
count
Species
setosa
versicolor
virginica
Density plot with facet
Use facet_grid() to subset plots by up to 2 variables
Function takes a formula as its main argument
Row variable on left, column variable on right
Use . if no variable needed
ggplot(data = iris, aes(x = Sepal.Length)) +
geom_density(fill = Species) +
facet_grid(Species ~ .)
Density plot with facet
0.0
0.4
0.8
1.2
0.0
0.4
0.8
1.2
0.0
0.4
0.8
1.2
setosaversicolorvirginica
5 6 7 8
Sepal.Length
density
Species
setosa
versicolor
virginica
Scale + axis control
Adding title labels, axes etc is similar to adding layers
Use the “+” operator with the appropriate functions
ggplot(USArrests, aes(x=Assault,y=Murder))
+ geom_point(aes(size=UrbanPop))
+ labs(title = "Violent Crime Rates by US State, 1973",
x = "Arrests for Assault (per 100 000)",
y = "Arrests for Murder (per 100 000)")
Scale + axis control
0
5
10
15
100 200 300
Arrests for Assault (per 100 000)
ArrestsforMurder(per100000)
UrbanPop
40
50
60
70
80
90
Violent Crime Rates by US State, 1973
Logged x axis
ggplot(USArrests, aes(x=Assault,y=Murder))
+ geom_point(aes(size=UrbanPop))
+ labs(title = "Violent Crime Rates by US State, 1973",
x = "Arrests for Assault (per 100 000)",
y = "Arrests for Murder (per 100 000)")
+ scale_x_log10()
Logged x axis
0
5
10
15
100
Arrests for Assault (per 100 000)
ArrestsforMurder(per100000)
UrbanPop
40
50
60
70
80
90
Violent Crime Rates by US State, 1973
Conclusion
ggplot2 works best with “long” format data
One row per observation, rather than different obs in different
columns
See “reshape2” package for easy conversion between “wide”
and “long” data formats
Where to learn more
Web documentation is a good place to start
http://docs.ggplot2.org
Lots of examples on blogs, stackoverflow etc.
We have only scratched the surface here!
Why not bring some example data visualisations to the next
meeting?
Tweet your plots @Sheffield_R_

More Related Content

What's hot (20)

PDF
Introduction to R for data science
Long Nguyen
 
PPTX
Decision tree
ShraddhaPandey45
 
PPTX
Missing Data and Causes
akanni azeez olamide
 
PDF
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
PDF
Data Analysis and Programming in R
Eshwar Sai
 
PPT
Slide3.ppt
butest
 
PPTX
Clustering Jerarquico
Liliana Pacheco
 
PPTX
Data Management in R
Sankhya_Analytics
 
PDF
R Programming: Transform/Reshape Data In R
Rsquared Academy
 
PDF
Introduction to R Graphics with ggplot2
izahn
 
PPT
Data Mining: Concepts and techniques: Chapter 13 trend
Salah Amean
 
PPTX
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
PPTX
Density based clustering
YaswanthHariKumarVud
 
PPTX
Decision Tree Learning
Md. Ariful Hoque
 
PDF
CART: Not only Classification and Regression Trees
Marc Garcia
 
PPTX
Decision tree
Karan Deopura
 
PDF
Window functions in MySQL 8.0
Mydbops
 
PPT
2.1 Data Mining-classification Basic concepts
Krish_ver2
 
PPTX
Clustering.pptx
Ramakrishna Reddy Bijjam
 
PPT
1.8 discretization
Krish_ver2
 
Introduction to R for data science
Long Nguyen
 
Decision tree
ShraddhaPandey45
 
Missing Data and Causes
akanni azeez olamide
 
R visualization: ggplot2, googlevis, plotly, igraph Overview
Olga Scrivner
 
Data Analysis and Programming in R
Eshwar Sai
 
Slide3.ppt
butest
 
Clustering Jerarquico
Liliana Pacheco
 
Data Management in R
Sankhya_Analytics
 
R Programming: Transform/Reshape Data In R
Rsquared Academy
 
Introduction to R Graphics with ggplot2
izahn
 
Data Mining: Concepts and techniques: Chapter 13 trend
Salah Amean
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
Density based clustering
YaswanthHariKumarVud
 
Decision Tree Learning
Md. Ariful Hoque
 
CART: Not only Classification and Regression Trees
Marc Garcia
 
Decision tree
Karan Deopura
 
Window functions in MySQL 8.0
Mydbops
 
2.1 Data Mining-classification Basic concepts
Krish_ver2
 
Clustering.pptx
Ramakrishna Reddy Bijjam
 
1.8 discretization
Krish_ver2
 

Similar to Intro to ggplot2 - Sheffield R Users Group, Feb 2015 (20)

PPTX
Data and donuts: Data Visualization using R
C. Tobin Magle
 
PDF
Q plot tutorial
Abhik Seal
 
PPTX
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Shubham Shah
 
PDF
Graphics in R
Kamal Gupta Roy
 
PDF
RDataMining slides-data-exploration-visualisation
Yanchang Zhao
 
PDF
Data Exploration and Visualization with R
Yanchang Zhao
 
PDF
Ggplot2 ch2
heba_ahmad
 
PDF
Data visualization-2.1
RenukaRajmohan
 
PDF
Elegant Graphics for Data Analysis with ggplot2
yannabraham
 
DOCX
Summerization notes for descriptive statistics using r
Ashwini Mathur
 
PDF
Data Visualization with ggplot2.pdf
CarlosTrujillo199971
 
PPTX
Exploratory Data Analysis
Umair Shafique
 
PDF
Table of Useful R commands.
Dr. Volkan OBAN
 
DOCX
R-ggplot2 package Examples
Dr. Volkan OBAN
 
PDF
VISIALIZACION DE DATA.pdf
Ivan Bautista Fuentes
 
PDF
Some R Examples[R table and Graphics] -Advanced Data Visualization in R (Some...
Dr. Volkan OBAN
 
PDF
R Visualization Assignment
Vassilis Kapatsoulias
 
PPTX
Data Exploration in R.pptx
Ramakrishna Reddy Bijjam
 
PPTX
R programming.pptx r language easy concept
MuhammadjunaidgulMuh1
 
PDF
data-visualization.pdf
Juan José Rivas
 
Data and donuts: Data Visualization using R
C. Tobin Magle
 
Q plot tutorial
Abhik Seal
 
Introduction to Data Visualization for Agriculture and Allied Sciences using ...
Shubham Shah
 
Graphics in R
Kamal Gupta Roy
 
RDataMining slides-data-exploration-visualisation
Yanchang Zhao
 
Data Exploration and Visualization with R
Yanchang Zhao
 
Ggplot2 ch2
heba_ahmad
 
Data visualization-2.1
RenukaRajmohan
 
Elegant Graphics for Data Analysis with ggplot2
yannabraham
 
Summerization notes for descriptive statistics using r
Ashwini Mathur
 
Data Visualization with ggplot2.pdf
CarlosTrujillo199971
 
Exploratory Data Analysis
Umair Shafique
 
Table of Useful R commands.
Dr. Volkan OBAN
 
R-ggplot2 package Examples
Dr. Volkan OBAN
 
VISIALIZACION DE DATA.pdf
Ivan Bautista Fuentes
 
Some R Examples[R table and Graphics] -Advanced Data Visualization in R (Some...
Dr. Volkan OBAN
 
R Visualization Assignment
Vassilis Kapatsoulias
 
Data Exploration in R.pptx
Ramakrishna Reddy Bijjam
 
R programming.pptx r language easy concept
MuhammadjunaidgulMuh1
 
data-visualization.pdf
Juan José Rivas
 
Ad

More from Paul Richards (12)

PDF
Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow
Paul Richards
 
PDF
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
Paul Richards
 
PDF
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Paul Richards
 
PPTX
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
Paul Richards
 
PDF
Introduction to knitr - May Sheffield R Users group
Paul Richards
 
PDF
Querying open data with R - Talk at April SheffieldR Users Gp
Paul Richards
 
PDF
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
Paul Richards
 
PPTX
Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Paul Richards
 
PPTX
Introduction to Shiny for building web apps in R
Paul Richards
 
PPTX
Sheffield R Jan 2015 - Using R to investigate parasite infections in Asian el...
Paul Richards
 
PDF
Introduction to data.table in R
Paul Richards
 
PDF
Dplyr and Plyr
Paul Richards
 
Sheffield_R_ July meeting - Interacting with R - IDEs, Git and workflow
Paul Richards
 
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
Paul Richards
 
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Paul Richards
 
How to win $10m - analysing DOTA2 data in R (Sheffield R Users Group - May)
Paul Richards
 
Introduction to knitr - May Sheffield R Users group
Paul Richards
 
Querying open data with R - Talk at April SheffieldR Users Gp
Paul Richards
 
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
Paul Richards
 
Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Paul Richards
 
Introduction to Shiny for building web apps in R
Paul Richards
 
Sheffield R Jan 2015 - Using R to investigate parasite infections in Asian el...
Paul Richards
 
Introduction to data.table in R
Paul Richards
 
Dplyr and Plyr
Paul Richards
 
Ad

Recently uploaded (20)

PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PPTX
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
PPT
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
PPTX
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
PDF
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PPTX
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
PPTX
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PDF
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
PDF
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PDF
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
PDF
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 

Intro to ggplot2 - Sheffield R Users Group, Feb 2015

  • 1. Introduction to ggplot22 Paul Richards, ScHARR, The University of Sheffield Thursday, February 26, 2015
  • 2. Introduction ggplot2 is a package written by Hadley Wickham Powerful but easy to use functions for 2D graphics Based on the “Grammar of Graphics” theory by Leland Wilkinson use install.packages() to install latest version
  • 3. Concepts ggplot2 works with data.frames aesthetic = a feature we can see on the graphic (shape, size, colour etc) map from data to aestheics (i.e. different colour per group) layer = geometric object + data/aesthetics + statistical transformation a graphic will also have scale(s) and a co-ordinate system may also have facets - subsetting plot by some characteristic(s)
  • 4. Quick note on “plot” The “plot” function in base R is just a wrapper for lots of methods Behaviour depends on what object is supplied Can require some manual tinkering to get it to work as required Example, using the “iris” data, plot petal length vs sepal length Different colour for each species Point size varies by sepal width
  • 5. Scatterplot with “plot” with(iris, plot(Sepal.Length, Petal.Length, col = Species, cex = Sepal.Width)) 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 1234567 Sepal.Length Petal.Length
  • 6. Problems Cannot specify dataset within function No legend, have to add manually via legend() which is fiddly to use Arguments are a bit “dumb” - we need to rescale Sepal.Width to get better point sizes Need to use different functions to add new geometric objects, e.g. regression lines
  • 7. Qplot qplot(Sepal.Length, Petal.Length, data = iris, color = Species, size = Sepal.Width) 2 4 6 5 6 7 8 Sepal.Length Petal.Length Species setosa versicolor virginica Sepal.Width 2.0 2.5 3.0 3.5 4.0
  • 8. Qplot() Qplot is the nearest equivalent to plot() in ggplot2 For single layer plots this is easy enough to use Use geom argument to change plot type
  • 9. Boxplot example qplot(Species, Sepal.Length, data = iris, geom="boxplot") 5 6 7 8 setosa versicolor virginica Species Sepal.Length
  • 10. Violin example qplot(Species, Sepal.Length, data = iris, geom="violin") 5 6 7 8 setosa versicolor virginica Species Sepal.Length
  • 11. Histogram example qplot(Sepal.Length, data = iris, fill = Species) 0 5 10 4 5 6 7 8 Sepal.Length count Species setosa versicolor virginica
  • 12. ggplot() For multilayer plots or where more flexibility is required ggplot() sets up the default data and aesthetic mappings add layers using the “+” operator and appropriate functions all aesthetic mappings are wrapped in aes() function global changes (e.g. set all points to “red”) go outside
  • 13. Iris scatterplot again ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point(aes(size = Sepal.Width)) 2 4 6 5 6 7 8 Sepal.Length Petal.Length Species setosa versicolor virginica Sepal.Width 2.0 2.5 3.0 3.5 4.0
  • 14. Alternative ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point(size = 5) 2 4 6 5 6 7 8 Sepal.Length Petal.Length Species setosa versicolor virginica
  • 15. Adding to plots ggplots are objects so you can save them as you go You can then add new layers etc to the saved object gg1 <- ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) + geom_point(aes(size = Sepal.Width)) gg2 <- gg1 + geom_smooth() gg2
  • 16. Iris plot with loess smoother 2 4 6 5 6 7 8 Sepal.Length Petal.Length Species setosa versicolor virginica Sepal.Width 2.0 2.5 3.0 3.5 4.0
  • 17. Add contours gg3 <- gg2 + geom_density2d() gg3
  • 18. Add contours 2 4 6 5 6 7 8 Sepal.Length Petal.Length Species setosa versicolor virginica Sepal.Width 2.0 2.5 3.0 3.5 4.0
  • 19. Note on statistical transformations The loess smoother and contours in the previous plot are not part of data In base plot we would have to calculate them first In ggplot2 the stat_*() functions do such tranformations for us Often the corresponding geom_*() function does this automatically For more flexibility, use the stat_*() function and specify the geom you need
  • 20. Histogram example using stat_bin stat_bin performs a 1d “binning” transformation i.e. a histogram transformation ggplot(data = iris, aes(x = Sepal.Length, fill = Species)) + stat_bin(binwidth=1,position="dodge")
  • 21. Histogram example using stat_bin 0 10 20 30 4 6 8 Sepal.Length count Species setosa versicolor virginica
  • 22. Density plot with facet Use facet_grid() to subset plots by up to 2 variables Function takes a formula as its main argument Row variable on left, column variable on right Use . if no variable needed ggplot(data = iris, aes(x = Sepal.Length)) + geom_density(fill = Species) + facet_grid(Species ~ .)
  • 23. Density plot with facet 0.0 0.4 0.8 1.2 0.0 0.4 0.8 1.2 0.0 0.4 0.8 1.2 setosaversicolorvirginica 5 6 7 8 Sepal.Length density Species setosa versicolor virginica
  • 24. Scale + axis control Adding title labels, axes etc is similar to adding layers Use the “+” operator with the appropriate functions ggplot(USArrests, aes(x=Assault,y=Murder)) + geom_point(aes(size=UrbanPop)) + labs(title = "Violent Crime Rates by US State, 1973", x = "Arrests for Assault (per 100 000)", y = "Arrests for Murder (per 100 000)")
  • 25. Scale + axis control 0 5 10 15 100 200 300 Arrests for Assault (per 100 000) ArrestsforMurder(per100000) UrbanPop 40 50 60 70 80 90 Violent Crime Rates by US State, 1973
  • 26. Logged x axis ggplot(USArrests, aes(x=Assault,y=Murder)) + geom_point(aes(size=UrbanPop)) + labs(title = "Violent Crime Rates by US State, 1973", x = "Arrests for Assault (per 100 000)", y = "Arrests for Murder (per 100 000)") + scale_x_log10()
  • 27. Logged x axis 0 5 10 15 100 Arrests for Assault (per 100 000) ArrestsforMurder(per100000) UrbanPop 40 50 60 70 80 90 Violent Crime Rates by US State, 1973
  • 28. Conclusion ggplot2 works best with “long” format data One row per observation, rather than different obs in different columns See “reshape2” package for easy conversion between “wide” and “long” data formats
  • 29. Where to learn more Web documentation is a good place to start http://docs.ggplot2.org Lots of examples on blogs, stackoverflow etc. We have only scratched the surface here! Why not bring some example data visualisations to the next meeting? Tweet your plots @Sheffield_R_