12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

millions of people. (The documentation of the longley dataset is not clear onthis topic.) Be very careful when you present plots like this — you don’t wantto be accused of creating chart junk (misleading graphics).Figure 17-9: Using data in tall format to put different variables in each panel.Creating a chart with groupsMany graphics types — but bar charts in particular — tend to display multiplegroups of data at the same time. Usually, you can distinguish different groups bytheir color or sometimes their shading.If you ever want to add different colors to your plot to distinguish betweendifferent data, you need to define groups in your lattice plot.Say you want to create a bar chart that differentiates whether a car has anautomatic or manual gearbox. The mtcars dataset has a column with this data,called am — this is a numeric vector with the value 0 for automatic and 1 formanual. You can use the ifelse() function to convert from numeric values to acharacter values “Automatic” and “Manual”:> mtcars$cars mtcars$am barchart(cars ~ mpg | factor(cyl), data=mtcars,+ group=am,+ scales=list(cex=0.5),+ layout=c(3, 1),+ )

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!