R语言ggplot2要素总结

模板

ggplot(data = <data> ) +
	<geom_xxxx> ( mapping = aes(<mapping>),
				stat = <stat>,
				position = <position>) +
	<coord_xxxx>(...) +
    <facet_xxxx>(...)

ggplot2基础

  • 定义数据(data),创建空图(plot object)。ggplot()
  • 指定几何图形(geoms – graphics shapes)展现数据。geom_xxxx()
  • 指定几何图形的特征(aesthetics – features)表现数值。aes()

In brief, the grammar tells us that a statistical graphic is a mapping from data to aesthetic attributes (colour, shape, size) of geometric objects (points, lines, bars). The plot may also contain statistical transformations of the data and is drawn on a specific coordinate system. Facetting can be used to generate the same plot for different subsets of the dataset. It is the combination of these independent components that make up a graphic.

geom & aes

常用geom以及aes如下表,许多geom还是有color、size、group等aes。

geomdescriptionaesthetics
geom_point()Data symbolsx, y, shape, fill
geom_line()Line (ordered on x)x, y, linetype
geom_path()Line (original order)x, y, linetype
geom_text()Text labelsx, y, label, angle, hjust, vjust
geom_rect()Rectanglesxmin, xmax, ymin, ymax, fill,linetype
geom_polygon()Polygonsx, y, fill, linetype
geom_segment()Line segmentsx, y, xend, yend, linetype
geom_bar()Barsx, fill, linetype, weight
geom_histogram()Histogramx, fill, linetype, weight
geom_boxplot()Boxplotsx, y, fill, weight
geom_density()Densityx, y, fill, linetype
geom_contour()Contour linesx, y, fill, linetype
geom_smooth()Smoothed linex, y, fill, linetype

data -> aesthetic -> geom

scale

color fill x y linetype shape size

ScaleDescriptionParameters
scale_x_continuous()Continuous axisexpand, trans
scale_x_discrete()Categorical axis
scale_x_date()Date axismajor, minor, format
scale_shape()Symbol shape legend
scale_linetype()Line pattern legend
scale_color_manual()Symbol/line color legendvalues
scale_fill_manual()Symbol/bar ll legendvalues
scale_size()Symbol size legendtrans, to
Common to most scalesname, breaks, labels, limits

Statistical transformation

Stat Description Parameters
stat_identity() No transformation -
stat_count() Counts -
stat_bin() Binning binwidth, origin
stat_smooth() Smoother method, se, n
stat_boxplot() Boxplot statistics width
stat_contour() Contours breaks

data -> scale -> stat -> aesthetic -> geom -> cord

geomstataes
geom_ablineabinecolour,linetype,size
geom_areaidentitycolour,fill,linetype,size,x,y
geom_barbincolour,fill,linetype,size,weight,x
geom_bin2dbin2dcolour,fill,linetype,size,weight,xmax,xmin,ymax,ymin
geom_blankidentity
geom_boxplotboxplotcolour,fill,lower,middle,size,upper,weight,x,ymax.ymin
geom_contourcontourcolour,linetype,size,weight,x
geom_crossbaridentitycolour,fill,linetype,size,x,y,ymax,ymin
geom_densitydensitycolour,fill,linetype,size,weight,x,y
geom_density2ddensity2dcolour,linetype,size,weight,x,y
geom_dotplotbindotcolour,fill,x,y
geom_errorbaridentitycolour,linetype,size,width,x,ymax,ymin
geom_errorbarhidentitycolour,linetype,size,width,x,ymax,ymin
geom_freqpolybincolour,linetype,size
geom_hexbinhexcolour,fill,size,x,y
geom_histogrambincolour,fill,linetype,size,weight,x
geom_hlinehlinecolour,linetype,size
geom_jitteridentitycolour,fill,shape,size,x,y
geom_lineidentitycolour,linetype,size,x,y
geom_linerangeidentitycolour,linetype,size,size,x,ymax,ymin
geom_mapidentitycolour,fill,linetype,size,x,y,map_id
geom_pathidentitycolour,linetype,size,x,y
geom_pointidentitycolour,fill,shape,size,x,y
geom_pointrangeidentitycolour,fill,linetype,shape,size,x,ymax,ymin
geom_polygonidentitycolour,fill,linetype,size,x,y
geom_quantilequantilecolour,linetype,size,weight,x,y
geom_rasteridentitycolour,fill,linetype,size,x,y
geom_rectidentitycolour,fill,linetype,size,xmax,xmin,ymax,ymin
geom_ribbonidentitycolour,fill,linetype,size,x,ymax,ymin
geom_rugidentitycolour,linetype,size
geom_segmentidentitycolour,linetype,size,x,xend.y.yend
geom_smoothsmoothaplha,colour,fill,linetype,size,weight,x,y
geom_stepidentitycolour,linetype,size,x,y
geom_textidentityangle,colour,hjust,label,size,size,vjust,x,y
geom_tileidentitycolour,fill,linetype,size,x,y
geom_violinydensityweigth,colour,fill,size,linetype,x,y
geom_vlinevlinecolour,linetype,size

facets: multipanel

themes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值