ݺߣ

ݺߣShare a Scribd company logo
Extend your toolbox with
Szymon Skorupinski
CERN IT Lightning Talks Session
2nd October 2015
R
R is...
? Open source version of S ;)
? Programming language
? Computing environment
? Designed especially for data
? analysis
? manipulation
? visualization
Example data set
? From UBS Prices & Earnings 2015 report
? Working hours required to buy iPhone 6 for 70 cities
Year;City;Name;What;Hours
2015;Amsterdam;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;49,75
2015;Athens;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;98,21
2015;Auckland;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;44,62
2015;Bangkok;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;149,57
2015;Barcelona;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;59,06
2015;Beijing;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;217,8
()
Example data set
? From UBS Prices & Earnings 2015 report
? Working hours required to buy iPhone 6 for 70 cities
Year;City;Name;What;Hours
2015;Amsterdam;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;49,75
2015;Athens;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;98,21
2015;Auckland;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;44,62
2015;Bangkok;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;149,57
2015;Barcelona;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;59,06
2015;Beijing;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;217,8
()
Reading data
data <- read.csv2("data.csv")
hours <- data$Hours
names(hours) <- data$City
Your first bar chart!
barplot(hours)
Extend Your Toolbox with R
Better sort data
hours <- sort(hours)
and plot it again
barplot(hours)
Extend Your Toolbox with R
with better x-axis labels
barplot(
hours,
las = 2)
Extend Your Toolbox with R
 and horizontally
barplot(
hours,
las = 2,
horiz = TRUE)
Extend Your Toolbox with R
plus with colors
barplot(
hours,
las = 2,
horiz = TRUE,
col = rainbow(length(hours)))
Extend Your Toolbox with R
and other minor changes
barplot(
hours,
las = 2,
horiz = TRUE,
col = rainbow(length(hours)),
axis.lty = 1,
main = "Working time to buy
iPhone 6 - in hours")
Extend Your Toolbox with R
Visualize median
abline(
v = median(hours),
lwd = 3)
Extend Your Toolbox with R
Another chart type
hist(
hours,
col = rainbow(7))
Extend Your Toolbox with R
Or both together?
par(mfrow = c(1,2))
Then draw both graphs again and you get
Extend Your Toolbox with R
Save your work
dev.print(
pdf,
"charts.pdf")
? Many other formats available
? jpg, png, svg, postscript, etc.
More graphics examples
From demo() function
This is only tip of the iceberg
? Of R graphics
? Quickly create publication ready graphs
? Only base package shown today
? Many others available, e.g.: lattice, ggplot2
? Of other vast R capabilities
? Statistics, analytics, machine learning etc.
? Extensible by over 7000 packages
? https://cran.r-project.org/web/packages
Try it!
? R - https://cran.r-project.org
? IDE for R - https://www.rstudio.com
? MOOC, e.g.
? R Programming on Coursera
? Interactive tutorial about R on R
? http://swirlstats.com
? Without installing anything C in your browser
? https://www.datacamp.com/swirl-r-tutorial
Questions?
Thank you!

More Related Content

Extend Your Toolbox with R

  • 1. Extend your toolbox with Szymon Skorupinski CERN IT Lightning Talks Session 2nd October 2015 R
  • 2. R is... ? Open source version of S ;) ? Programming language ? Computing environment ? Designed especially for data ? analysis ? manipulation ? visualization
  • 3. Example data set ? From UBS Prices & Earnings 2015 report ? Working hours required to buy iPhone 6 for 70 cities Year;City;Name;What;Hours 2015;Amsterdam;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;49,75 2015;Athens;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;98,21 2015;Auckland;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;44,62 2015;Bangkok;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;149,57 2015;Barcelona;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;59,06 2015;Beijing;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;217,8 ()
  • 4. Example data set ? From UBS Prices & Earnings 2015 report ? Working hours required to buy iPhone 6 for 70 cities Year;City;Name;What;Hours 2015;Amsterdam;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;49,75 2015;Athens;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;98,21 2015;Auckland;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;44,62 2015;Bangkok;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;149,57 2015;Barcelona;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;59,06 2015;Beijing;Working time required to buy..;1 iPhone 6 16 GB, in hrs.;217,8 ()
  • 5. Reading data data <- read.csv2("data.csv") hours <- data$Hours names(hours) <- data$City
  • 6. Your first bar chart! barplot(hours)
  • 8. Better sort data hours <- sort(hours)
  • 9. and plot it again barplot(hours)
  • 11. with better x-axis labels barplot( hours, las = 2)
  • 15. plus with colors barplot( hours, las = 2, horiz = TRUE, col = rainbow(length(hours)))
  • 17. and other minor changes barplot( hours, las = 2, horiz = TRUE, col = rainbow(length(hours)), axis.lty = 1, main = "Working time to buy iPhone 6 - in hours")
  • 19. Visualize median abline( v = median(hours), lwd = 3)
  • 23. Or both together? par(mfrow = c(1,2)) Then draw both graphs again and you get
  • 25. Save your work dev.print( pdf, "charts.pdf") ? Many other formats available ? jpg, png, svg, postscript, etc.
  • 26. More graphics examples From demo() function
  • 27. This is only tip of the iceberg ? Of R graphics ? Quickly create publication ready graphs ? Only base package shown today ? Many others available, e.g.: lattice, ggplot2 ? Of other vast R capabilities ? Statistics, analytics, machine learning etc. ? Extensible by over 7000 packages ? https://cran.r-project.org/web/packages
  • 28. Try it! ? R - https://cran.r-project.org ? IDE for R - https://www.rstudio.com ? MOOC, e.g. ? R Programming on Coursera ? Interactive tutorial about R on R ? http://swirlstats.com ? Without installing anything C in your browser ? https://www.datacamp.com/swirl-r-tutorial