3 / 1 5 / 2 0 1 2 Introduction to CAS RPM Seminar Steve Berman, FCAS, MAAA March 19, 2012 Jim Guszcza, FCAS, MAAA R – Graphics Charts Scatterplots Histograms Boxplots Other visualizations 1
3 / 1 5 / 2 0 1 2 R Graphics • R offers a large versatility in graphics. It’s easy to create a simple plot, but graphs can be customized in ways that are hard to do in Excel or most applications Hint: you can alw ays click “ctrl-l” to clear the screen 2 plot • plot is the simplest graphics command. It’s a generic plotting function. Creates a graphics frame and allows drawing of data series. Can create quick plots or customize the output – Chart type ( type ) – Titles ( main , sub ) – Axes ( axis ) – Legends ( legend ) – Colors ( col ) – Sizes ( lwd , cex ) – Data labels ( text , mtext ) • lines draws additional lines on an existing graph • par controls graphical parameters Hint: you can alw ays click “ctrl-l” to clear the screen 3 2
3 / 1 5 / 2 0 1 2 Bar charts • Use barplot function, similar to plot • Grouped bars • Stacked bars • Vertical or horizontal Hint: you can alw ays click “ctrl-l” to clear the screen 4 Exercise • Create a bar chart showing losses by accident month • Extra credit: split by coverage, 2007 only Hint: you can alw ays click “ctrl-l” to clear the screen 5 3
3 / 1 5 / 2 0 1 2 Histograms • There are several functions for creating simple histograms – hist – truehist • Can adjust size of bins, color, a few other options Hint: you can alw ays click “ctrl-l” to clear the screen 6 boxplot • Use to get a graphical representation of distribution • Show center of distributions, outliers • Grouping by subcategories • Tip: 2-D version of a boxplot exists, called a bagplot (in aplpack library) Hint: you can alw ays click “ctrl-l” to clear the screen 7 4
3 / 1 5 / 2 0 1 2 Scatterplots • Two dimensional plot (where x axis points not ordered) • Use plot function (type= ‘p’) or other functions Hint: you can alw ays click “ctrl-l” to clear the screen 8 Exercise • Modify the price / quantity scatterplot for the following: – Pricing changes in January – mark all January and February dots in a different color – Change the dots so that the size of the dots is proportional to sales (under $1M, $1M-2M, $2M+ ) (size of dots using cex ) Hint: you can alw ays click “ctrl-l” to clear the screen 9 5
3 / 1 5 / 2 0 1 2 Q-Q plots • To test that data came from specific distribution – One axis is empirical distribution – One axis is theoretical distribution – This example uses plot and abline Hint: you can alw ays click “ctrl-l” to clear the screen 10 Correlations • Get more information than from cor () function – pairs – heatmap ee.risk patient.risk payer.consol clinical.consol cost.control oa.activity quality.init innovation community.activity standardization ee.risk patient.risk payer.consol clinical.consol cost.control oa.activity quality.init innovation ommunity.activity standardization Hint: you can alw ays click “ctrl-l” to clear the screen 11 6
3 / 1 5 / 2 0 1 2 Other visualizations • Several packages exist which add to visualizations – lattice – ggplot – maps – VMRLGen – Many more… Hint: you can alw ays click “ctrl-l” to clear the screen 12 7
Recommend
More recommend