Database Reference
In-Depth Information
Descriptive Plots
> library(lattice)
> install.packages(latticeExtra)
> library(latticeExtra)
lattice and latticeExtra are useful packages for data visualization. lattice comes with generic
functions to create trellis graphics, and allows extensive customization via user-control para-
meters. In the following examples, we take a closer look at foreclosures grouped by median
household income per tract, using tools available in the lattice packages.
We can first construct a new variable that groups the median household income into two
groups. Group one contains tracts that are higher than the national median household income
(above $50K); group two contains tracts that are lower than national median household in-
come:
> IncomeLevels<-as.factor((ct$medianHouseholdIncome)>50000)
> IncomeLevels
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE ...
The IncomeLevels can then be renamed as such:
> levels(IncomeLevels) <- c("<50K", ">50K")
> IncomeLevels
[1] <50K <50K <50K <50K <50K <50K <50K <50K <50K ...
Now we can construct the plot seen in Figure 2-3 :
> print(stripplot(IncomeLevels ~ jitter(ct$FCs),
main = list(
"Foreclosures grouped by National Median Household
Income",
cex=1),
sub=list("Greater or less than $50,000", cex=1),
xlab = "foreclosures",
ylab=" household median income",
aspect=.3,col="light blue", pch=2 ) +
as.layer(bwplot(IncomeLevels ~ ct$FCs,
varwidth=TRUE, box.ratio=0.4, col="blue",
pch="|"))
)
Two graphical functions are used in this case: stripplot() and bwplot() . stripplot plots
each number of foreclosures per tract, while bwplot provides a boxplot. The + between the
two functions tells R that the graph is not complete, and as.layer() allows us to overlay the
Search WWH ::




Custom Search