Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- LA EMPRESA Y LA CONTABILIDAD by jatencio23 2618 views
- BULLYING Y FUNCIONAMIENTO FAMILIAR by Teofilo ccoicca 41009 views
- Perspectiva mex by Pablo Torres 795 views
- Historia de la economía mexicana by Karla H'Vigil 611 views
- Sugerencias para la planificación p... by alo_jl 24215 views
- Ciclo Celular by Valeria Apablaza 17556 views

3,179 views

3,013 views

3,013 views

Published on

Published in:
Technology

No Downloads

Total views

3,179

On SlideShare

0

From Embeds

0

Number of Embeds

8

Shares

0

Downloads

0

Comments

0

Likes

6

No embeds

No notes for slide

- 1. A Survey of R Graphics<br />June 18 2009<br />R Users<br />Group of LA<br />Michael E. Driscoll<br />Principal, Dataspora<br />mike@dataspora.com<br />
- 2. “The sexy job in the next ten years will be statisticians…”<br />- Hal Varian<br />
- 3.
- 4. Hypothesis<br />(from Jessica Hagy’s thisisindexed.com)<br />
- 5. Munge & Model<br />gdp <- read.csv('gdp.csv')hours <- read.csv('hours.csv')gdp.hours <- merge(hours,gdp)gdp.hours$freetime <- 4380 - gdp.hours$hoursattach(gdp.hours)plot(freetime ~ gdp)m <- lm(freetime ~ gdp,data=gdp.hours)abline(m,col=3,lw=2)pm <- loess(freetime ~ gdp)lines(spline(gdp,fitted(pm)))<br />
- 6. Visualization<br />library(ggplot2)<br />qplot(gdp,freetime,<br />data=gdp.hours,<br />geom=c("point",<br /> "smooth"),<br />span=1)<br />
- 7. basic graphics<br />
- 8. R’s Two Graphics Systems<br />
- 9. plot() graphs objects<br />plot(freetime ~ gdp, <br /> data=gdp.hours)<br />model <- lm(freetime ~ gdp,<br /> data=gdp.hours)<br />abline(model) <br />
- 10. plot() graphs objects<br />abline(model,<br />col="red",<br />lwd=3)<br />
- 11. par sets graphical parameters<br />par(pch=20, <br />cex=5,<br />col="#5050a0BB")<br />RGB hex<br />alpha blending!<br />plot(freetime ~ gdp, data=gdp.hours)<br />help(par)<br />
- 12. par sets graphical parameters<br />parameters<br />for par()<br />pch<br />col<br />adj<br />srt<br />pt.cex<br />graphing functions<br />points()<br />text()<br />xlab()<br />legend()<br />
- 13. Paneling Graphics<br />By setting one parameter in particular, mfrow, we can partition the graphics display to give us a multiple framework in which to panel our plots, rowwise.<br />par(mfrow= c( nrow, ncol))<br />Number of rows<br />Number of columns<br />
- 14. Paneling Graphics<br />par(mfrow=c(2,2))<br />hist(D$wg, main='Histogram',xlab='Weight Gain', ylab ='Frequency', col=heat.colors(14))<br />boxplot(wg.7a$wg, wg.8a$wg, wg.9a$wg, wg.10a$wg, wg.11a$wg, wg.12p$wg, main='Weight Gain', ylab='Weight Gain (lbs)',<br />xlab='Shift', names = c('7am','8am','9am','10am','11am','12pm'))<br />plot(D$metmin,D$wg,main='Met Minutes vs. Weight Gain', xlab='Mets (min)',ylab='Weight Gain (lbs)',pch=2)<br />plot(t1,D2$Intel,type="l",main='Closing Stock Prices',xlab='Time',ylab='Price $')<br />lines(t1,D2$DELL,lty=2)<br />
- 15. Paneling Graphics<br />
- 16. Working with Graphics Devices<br />Starting up a new graphic X11 window<br />x11()<br />To write graphics to a file, open a device, write to it, close.<br />pdf(“mygraphic.pdf”,width=7,height=7) <br />plot(x)<br />dev.off()<br />In Linux, the package “Cairo “ is recommended for a device that renders high-quality vector and raster images (alpha blending!). The command would read Cairo(“mygraphic.pdf”, …<br />Common gotcha: under non-interactive sessions, you should explicitly invoke a print command to send a plot object to an open device. For example <br /> print(plot(x))<br />
- 17. library(ggplot2)<br />
- 18. ggplot2 =grammar of graphics<br />
- 19. ggplot2 =grammar ofgraphics<br />
- 20. Visualizing 50,000 Diamonds with ggplot2<br />
- 21. qplot(carat, price, data = diamonds)<br />
- 22. qplot(log(carat), log(price), data = diamonds)<br />qplot(carat, price, log=“xy”, data = diamonds)<br />OR<br />
- 23. qplot(log(carat), log(price), data = diamonds, <br />alpha = I(1/20))<br />
- 24. qplot(log(carat), log(price), data = diamonds, <br />alpha = I(1/20), colour=color)<br />
- 25. Achieving small multiples with “facets”<br />qplot(log(carat), log(price), data = diamonds, alpha=I(1/20)) + facet_grid(. ~ color)<br />
- 26. old<br />new<br />qplot(color, price/carat, <br />data = diamonds, alpha = I(1/20), geom=“jitter”)<br />qplot(color, price/carat, <br />data = diamonds,<br />geom=“boxplot”)<br />
- 27.
- 28. library(lattice)<br />
- 29. lattice = trellis<br />(source: http://lmdvr.r-forge.r-project.org )<br />
- 30. visualizing six dimensions<br />of MLB pitches with lattice<br />
- 31. xyplot(x ~ y, data=pitch)<br />
- 32. xyplot(x ~ y, groups=type, data=pitch)<br />
- 33. xyplot(x ~ y | type, data=pitch)<br />
- 34. xyplot(x ~ y | type, data=pitch,<br />fill.color = pitch$color,<br />panel = function(x,y, fill.color, …, subscripts) {<br /> fill <- fill.color[subscripts]<br />panel.xyplot(x,y, fill= fill, …) })<br />
- 35. xyplot(x ~ y | type, data=pitch,<br />fill.color = pitch$color,<br />panel = function(x,y, fill.color, …, subscripts) {<br /> fill <- fill.color[subscripts]<br />panel.xyplot(x, y, fill= fill, …) })<br />
- 36. A Story of Two Pitchers<br />Hamels<br />Webb<br />
- 37. list of latticefunctions<br />densityplot(~ speed | type, data=pitch)<br />
- 38. plotting big data<br />
- 39. xyplotwith 1m points = Bad Idea Jeans<br />xyplot(log(price)~log(carat),data=diamonds)<br />
- 40. efficient plotting with hexbinplot<br />hexbinplot(log(price)~log(carat),data=diamonds,xbins=40)<br />
- 41. 100<br />thousand <br />gene measures<br />
- 42. efficient plotting with geneplotter<br />
- 43. beautiful colors with Colorspace<br />library(“Colorspace”)<br />red <- LAB(50,64,64)<br />blue <- LAB(50,-48,-48)<br />mixcolor(10, red, blue)<br />
- 44. R-->web<br />
- 45. LinuxApacheMySQLR<br />http://labs.dataspora.com/gameday<br />
- 46.
- 47.
- 48. Configuring rapache<br />Hello world script<br />setContentType("text/html")<br />png("/var/www/hello.png")<br />plot(sample(100,100),col=1:8,pch=19)<br />dev.off()<br />cat("<html>")<br />cat("<body>")<br />cat("<h1>hello world</h1>")<br />cat('<imgsrc="../hello.png"')<br />cat("</body>")<br />cat("</html>")<br />
- 49. Data Visualization References<br />ggplot2: Elegant Graphics for Data Analysis<br />by Hadley Wickham<br />http://had.co.nz/ggplot2<br />Lattice: Multivariate Data Visualization with R<br />by DeepayanSarkar<br />http://lmdvr.r-forge.r-project.org/<br />

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment