您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > ggplot2-cheatsheet
GraphicalPrimitivesDataVisualizationwithggplot2CheatSheetRStudio®isatrademarkofRStudio,Inc.•CCBYRStudio•info@rstudio.com•844-448-1212•rstudio.comGeoms-Useageomtorepresentdatapoints,usethegeom’saestheticpropertiestorepresentvariables.Eachfunctionreturnsalayer.OneVariablea+geom_area(stat=bin)x,y,alpha,color,fill,linetype,sizeb+geom_area(aes(y=..density..),stat=bin)a+geom_density(kernel=gaussian)x,y,alpha,color,fill,linetype,size,weightb+geom_density(aes(y=..county..))a+geom_dotplot()x,y,alpha,color,filla+geom_freqpoly()x,y,alpha,color,linetype,sizeb+geom_freqpoly(aes(y=..density..))a+geom_histogram(binwidth=5)x,y,alpha,color,fill,linetype,size,weightb+geom_histogram(aes(y=..density..))Discreteb-ggplot(mpg,aes(fl))b+geom_bar()x,alpha,color,fill,linetype,size,weightContinuousa-ggplot(mpg,aes(hwy))TwoVariablesContinuousFunctionDiscreteX,DiscreteYh-ggplot(diamonds,aes(cut,color))h+geom_jitter()x,y,alpha,color,fill,shape,sizeDiscreteX,ContinuousYg-ggplot(mpg,aes(class,hwy))g+geom_bar(stat=identity)x,y,alpha,color,fill,linetype,size,weightg+geom_boxplot()lower,middle,upper,x,ymax,ymin,alpha,color,fill,linetype,shape,size,weightg+geom_dotplot(binaxis=y,stackdir=center)x,y,alpha,color,fillg+geom_violin(scale=area)x,y,alpha,color,fill,linetype,size,weightContinuousX,ContinuousYf-ggplot(mpg,aes(cty,hwy))f+geom_blank()(Usefulforexpandinglimits)f+geom_jitter()x,y,alpha,color,fill,shape,sizef+geom_point()x,y,alpha,color,fill,shape,sizef+geom_quantile()x,y,alpha,color,linetype,size,weightf+geom_rug(sides=bl)alpha,color,linetype,sizef+geom_smooth(method=lm)x,y,alpha,color,fill,linetype,size,weightf+geom_text(aes(label=cty))x,y,label,alpha,angle,color,family,fontface,hjust,lineheight,size,vjustThreeVariablesm+geom_contour(aes(z=z))x,y,z,alpha,colour,linetype,size,weightseals$z-with(seals,sqrt(delta_long^2+delta_lat^2))m-ggplot(seals,aes(long,lat))j-ggplot(economics,aes(date,unemploy))j+geom_area()x,y,alpha,color,fill,linetype,sizej+geom_line()x,y,alpha,color,linetype,sizej+geom_step(direction=hv)x,y,alpha,color,linetype,sizeContinuousBivariateDistributioni-ggplot(movies,aes(year,rating))i+geom_bin2d(binwidth=c(5,0.5))xmax,xmin,ymax,ymin,alpha,color,fill,linetype,size,weighti+geom_density2d()x,y,alpha,colour,linetype,sizei+geom_hex()x,y,alpha,colour,fillsizee+geom_segment(aes(xend=long+delta_long,yend=lat+delta_lat))x,xend,y,yend,alpha,color,linetype,sizee+geom_rect(aes(xmin=long,ymin=lat,xmax=long+delta_long,ymax=lat+delta_lat))xmax,xmin,ymax,ymin,alpha,color,fill,linetype,sizec+geom_polygon(aes(group=group))x,y,alpha,color,fill,linetype,sizee-ggplot(seals,aes(x=long,y=lat))m+geom_raster(aes(fill=z),hjust=0.5,vjust=0.5,interpolate=FALSE)x,y,alpha,fill(fast)m+geom_tile(aes(fill=z))x,y,alpha,color,fill,linetype,size(slow)k+geom_crossbar(fatten=2)x,y,ymax,ymin,alpha,color,fill,linetype,sizek+geom_errorbar()x,ymax,ymin,alpha,color,linetype,size,width(alsogeom_errorbarh())k+geom_linerange()x,ymin,ymax,alpha,color,linetype,sizek+geom_pointrange()x,y,ymin,ymax,alpha,color,fill,linetype,shape,sizeVisualizingerrordf-data.frame(grp=c(A,B),fit=4:5,se=1:2)k-ggplot(df,aes(grp,fit,ymin=fit-se,ymax=fit+se))d+geom_path(lineend=butt,linejoin=round’,linemitre=1)x,y,alpha,color,linetype,sized+geom_ribbon(aes(ymin=unemploy-900,ymax=unemploy+900))x,ymax,ymin,alpha,color,fill,linetype,sized-ggplot(economics,aes(date,unemploy))c-ggplot(map,aes(long,lat))data-data.frame(murder=USArrests$Murder,state=tolower(rownames(USArrests)))map-map_data(state)l-ggplot(data,aes(fill=murder))l+geom_map(aes(map_id=state),map=map)+expand_limits(x=map$long,y=map$lat)map_id,alpha,color,fill,linetype,sizeMapsABCBasicsBuildagraphwithggplot()orqplot()ggplot2isbasedonthegrammarofgraphics,theideathatyoucanbuildeverygraphfromthesamefewcomponents:adataset,asetofgeoms—visualmarksthatrepresentdatapoints,andacoordinatesystem.Todisplaydatavalues,mapvariablesinthedatasettoaestheticpropertiesofthegeomlikesize,color,andxandylocations.GraphicalPrimitivesDataVisualizationwithggplot2CheatSheetRStudio®isatrademarkofRStudio,Inc.•CCBYRStudio•info@rstudio.com•844-448-1212•rstudio.comLearnmoreatdocs.ggplot2.org•ggplot20.9.3.1•Updated:3/15Geoms-Useageomtorepresentdatapoints,usethegeom’saestheticpropertiestorepresentvariablesBasicsOneVariablea+geom_area(stat=bin)x,y,alpha,color,fill,linetype,sizeb+geom_area(aes(y=..density..),stat=bin)a+geom_density(kernal=gaussian)x,y,alpha,color,fill,linetype,size,weightb+geom_density(aes(y=..county..))a+geom_dotplot()x,y,alpha,color,filla+geom_freqpoly()x,y,alpha,color,linetype,sizeb+geom_freqpoly(aes(y=..density..))a+geom_histogram(binwidth=5)x,y,alpha,color,fill,linetype,size,weightb+geom_histogram(aes(y=..density..))Discretea-ggplot(mpg,aes(fl))b+geom_bar()x,alpha,color,fill,linetype,size,weightContinuousa-ggplot(mpg,aes(hwy))TwoVariablesDiscreteX,DiscreteYh-ggplot(diamonds,aes(cut,color))h+geom_jitter()x,y,alpha,color,fill,shape,sizeDiscreteX,ContinuousYg-ggplot(mpg,aes(class,hwy))g+geom_bar(stat=identity)x,y,alpha,color,fill,lin
本文标题:ggplot2-cheatsheet
链接地址:https://www.777doc.com/doc-5224913 .html