1. faceting: automatically laying out multiple plots on a page.
Split data into subsets, then plots each subset into a different panel on the page.
2. Coordinate system: Control how the two independent position scales are combined to create a 2d coordinate system.
like Cartesian, ploar
7.2 Faceting:
1. facet_grid: 2d
facet_wrap: 1d, but wrapped into 2d to save space
2. facet_grid(row_vars~col_vars)
3. margins=TRUE or FALSE
4. facet_wrap:
1) it's useful if you have a single variable with many levels and want to arrange the plots in a more space efficient manner.
( similar to lattice)
e.g. movie$decade=round_any(movie$year,10,floor)
qplot(rating, ..density..,data=subset(movies,decade>1890), geom="histogram", binwidth=0.5)+facet_wrap(~decade,ncol=6)
2) ~var1+var2+var3...
5. controlling scales
1) scales="free" : x and y are free, can vary across panels.
2) scales=“free_y": y is free and x is fixed
3) scales="free_x"
4)scales="fixed"
free scales are particularly useful when displaying multiple time series measured on different scales.
6. Grouping vs. faceting
note: grouping-draw on a plot
faceting: draw on multiple plots
grouping might overlap a lot using scatterplot. faceting might be better
compare regression line, grouping might be better
faceting will also with with much larger number of groups, you can compare 2 variables simultaneously.
faceting work well with scales varying across panels using free scales.
7. dodging vs. faceting
faceting can acheive similar effects to dodging. The main difference is the labelling.
e.g. qplot(color,data=diamonds, geom="bar", fill=cut, position="dodge")
qplot(cut,data=diamonds,geom=”bar“,fill=cut)+facet_grid(.~ color)
8. continuous variables
facet by continuous variables, but need to convert them into category variables first.
cut_interval(x,n=10): specify number of bins
cut_interval(x,length=1): specify the length of each interval
cut_number(x,n=10): divide the data into n bins but each containing the same number of points.
7.3.3 Cartesian
set limits:
coord_cartesian: xlim=... ylim=....
flipping the axes:
coord_filp()
transformation:
coord_trans
qplot(carat,price,data=diamonds,log="xy”)+geom_smooth(method="lm")
last_plot()+coord_trans(x="pow10",y="pow10)
Equal scales:
coord_equal(): ensure that the x and y axes have equal scales.
with ratio parameter