GGplot in R: Positioning--faceting and coordinate system

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值