Package: ggplot2

Thomas Lin Pedersen

ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics

A system for 'declaratively' creating graphics, based on "The Grammar of Graphics". You provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.

Authors:Hadley Wickham [aut], Winston Chang [aut], Lionel Henry [aut], Thomas Lin Pedersen [aut, cre], Kohske Takahashi [aut], Claus Wilke [aut], Kara Woo [aut], Hiroaki Yutani [aut], Dewey Dunnington [aut], Teun van den Brand [aut], Posit, PBC [cph, fnd]

ggplot2.pdf |ggplot2.html
ggplot2/json (API)

# Install ggplot2 in R:
install.packages('ggplot2', repos = c('', ''))

Peer review:

Bug tracker:

  • diamonds - Prices of over 50,000 round cut diamonds
  • economics - US economic time series
  • economics_long - US economic time series
  • faithfuld - 2d density estimate of Old Faithful data
  • luv_colours - 'colors()' in Luv space
  • midwest - Midwest demographics
  • mpg - Fuel economy data from 1999 to 2008 for 38 popular models of cars
  • msleep - An updated and expanded version of the mammals sleep dataset
  • presidential - Terms of 12 presidents from Eisenhower to Trump
  • seals - Vector field of seal movements
  • txhousing - Housing sales in TX



573 exports 6.4k stars 19.72 score 27 dependencies 6795 dependents 1.7M downloads

Last updated 1 days agofrom:ba0b18ab7bcc37e86b971e382710ce2cac6ed60e


Aesthetic specifications

Rendered fromggplot2-specs.Rmdusingknitr::rmarkdownon Jun 18 2024.

Last update: 2024-04-29
Started: 2015-08-14

Extending ggplot2

Rendered fromextending-ggplot2.Rmdusingknitr::rmarkdownon Jun 18 2024.

Last update: 2024-05-20
Started: 2015-08-05

Introduction to ggplot2

Rendered fromggplot2.Rmdusingknitr::rmarkdownon Jun 18 2024.

Last update: 2023-12-18
Started: 2023-09-11

Using ggplot2 in packages

Rendered fromggplot2-in-packages.Rmdusingknitr::rmarkdownon Jun 18 2024.

Last update: 2024-05-20
Started: 2019-06-04

Readme and manuals

Help Manual

Help pageTopics
Add components to a plot%+%
Construct aesthetic mappingsaes
Colour related aesthetics: colour, fill, and alphaaes_colour_fill_alpha color colour fill
Control aesthetic evaluationaes_eval after_scale after_stat stage stat
Aesthetics: groupingaes_group_order group
Differentiation related aesthetics: linetype, size, shapeaes_linetype_size_shape linetype shape size
Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yendaes_position x xend xmax xmin y yend ymax ymin
Create an annotation layerannotate
Annotation: Custom grobannotation_custom
Annotation: log tick marksannotation_logticks
Annotation: a mapannotation_map
Annotation: high-performance rectangular tilingannotation_raster
Create a ggplot layer appropriate to a particular data typeautolayer
Tailoring plots to particular data typesautomatic_plotting
Create a complete ggplot appropriate to a particular data typeautoplot
Create a layer of map bordersborders
Cartesian coordinatescoord_cartesian
Cartesian coordinates with fixed "aspect ratio"coord_equal coord_fixed
Cartesian coordinates with x and y flippedcoord_flip
Map projectionscoord_map coord_quickmap
Polar coordinatescoord_polar coord_radial
Transformed Cartesian coordinate systemcoord_trans
Visualise sf objectsCoordSf coord_sf GeomSf geom_sf geom_sf_label geom_sf_text ggsf StatSf stat_sf
Discretise numeric data into categoricalcut_interval cut_number cut_width
Prices of over 50,000 round cut diamondsdiamonds
Key glyphs for legendsdraw_key draw_key_abline draw_key_blank draw_key_boxplot draw_key_crossbar draw_key_dotplot draw_key_label draw_key_linerange draw_key_path draw_key_point draw_key_pointrange draw_key_polygon draw_key_rect draw_key_smooth draw_key_text draw_key_timeseries draw_key_vline draw_key_vpath
US economic time serieseconomics economics_long
Theme elementselement_blank element_line element_rect element_text margin rel
Expand the plot limits, using dataexpand_limits
Generate expansion vector for scalesexpand_scale expansion
Lay out panels in a gridfacet_grid
Wrap a 1d ribbon of panels into 2dfacet_wrap
2d density estimate of Old Faithful datafaithfuld
Fortify a model with data.fortify
Reference lines: horizontal, vertical, and diagonalgeom_abline geom_hline geom_vline
Bar chartsgeom_bar geom_col stat_count
Heatmap of 2d bin countsgeom_bin2d geom_bin_2d stat_bin2d stat_bin_2d
Draw nothinggeom_blank
A box and whiskers plot (in the style of Tukey)geom_boxplot stat_boxplot
2D contours of a 3D surfacegeom_contour geom_contour_filled stat_contour stat_contour_filled
Count overlapping pointsgeom_count stat_sum
Vertical intervals: lines, crossbars & errorbarsgeom_crossbar geom_errorbar geom_linerange geom_pointrange
Smoothed density estimatesgeom_density stat_density
Contours of a 2D density estimategeom_density2d geom_density2d_filled geom_density_2d geom_density_2d_filled stat_density2d stat_density2d_filled stat_density_2d stat_density_2d_filled
Dot plotgeom_dotplot
Horizontal error barsgeom_errorbarh
Histograms and frequency polygonsgeom_freqpoly geom_histogram stat_bin
Draw a function as a continuous curvegeom_function stat_function
Hexagonal heatmap of 2d bin countsgeom_hex stat_binhex stat_bin_hex
Jittered pointsgeom_jitter
Textgeom_label geom_text
Polygons from a reference mapgeom_map
Connect observationsgeom_line geom_path geom_step
A quantile-quantile plotgeom_qq geom_qq_line stat_qq stat_qq_line
Quantile regressiongeom_quantile stat_quantile
Rectanglesgeom_raster geom_rect geom_tile
Ribbons and area plotsgeom_area geom_ribbon stat_align
Rug plots in the marginsgeom_rug
Line segments and curvesgeom_curve geom_segment
Smoothed conditional meansgeom_smooth stat_smooth
Line segments parameterised by location, direction and distancegeom_spoke stat_spoke
Violin plotgeom_violin stat_ydensity
Extract alt text from a plotalt_text get_alt_text
Get, set, and modify the active theme%+replace% get_theme replace_theme set_theme theme_get theme_replace theme_set theme_update update_theme
Create a new ggplotggplot
Create a new ggproto objectggproto ggproto_parent is.ggproto
Save a ggplot (or other grid object) with sensible defaultsggsave
Complete themestheme_bw theme_classic theme_dark theme_gray theme_grey theme_light theme_linedraw theme_minimal theme_test theme_void
Axis guideguide_axis
Axis with logarithmic tick marksguide_axis_logticks
Stacked axis guidesguide_axis_stack
Angle axis guideguide_axis_theta
A binned version of guide_legendguide_bins
Continuous colour bar guideguide_colorbar guide_colourbar
Discretized colourbar guideguide_colorsteps guide_coloursteps
Custom guidesguide_custom
Legend guideguide_legend
Empty guideguide_none
Set guides for each scaleguides
A selection of summary functions from Hmischmisc mean_cl_boot mean_cl_normal mean_sdl median_hilow
Label with mathematical expressionslabel_bquote
Construct labelling specificationlabeller
Useful labeller functionslabellers label_both label_context label_parsed label_value label_wrap_gen
Modify axis, legend, and plot labelsggtitle labs xlab ylab
Layer geometry displaylayer_geoms
Layer position adjustmentslayer_positions
Layer statistical transformationslayer_stats
Set scale limitslims xlim ylim
'colors()' in Luv spaceluv_colours
Calculate mean and standard error of the meanmean_se
Midwest demographicsmidwest
Fuel economy data from 1999 to 2008 for 38 popular models of carsmpg
An updated and expanded version of the mammals sleep datasetmsleep
Dodge overlapping objects side-to-sideposition_dodge position_dodge2
Don't adjust positionposition_identity
Jitter points to avoid overplottingposition_jitter
Simultaneously dodge and jitterposition_jitterdodge
Nudge points a fixed distanceposition_nudge
Stack overlapping objects on top of each anotherposition_fill position_stack
Terms of 12 presidents from Eisenhower to Trumppresidential
Explicitly draw plotplot.ggplot print.ggplot
Format or print a ggproto objectformat.ggproto print.ggproto
Quick plotqplot quickplot
Compute the "resolution" of a numeric vectorresolution
Alpha transparency scalesscale_alpha scale_alpha_binned scale_alpha_continuous scale_alpha_date scale_alpha_datetime scale_alpha_discrete scale_alpha_ordinal
Positional scales for binning continuous data (x & y)scale_x_binned scale_y_binned
Sequential, diverging and qualitative colour scales from ColorBrewerscale_color_brewer scale_color_distiller scale_color_fermenter scale_colour_brewer scale_colour_distiller scale_colour_fermenter scale_fill_brewer scale_fill_distiller scale_fill_fermenter
Continuous and binned colour scalesscale_color_binned scale_color_continuous scale_colour_binned scale_colour_continuous scale_fill_binned scale_fill_continuous
Discrete colour scalesscale_color_discrete scale_colour_discrete scale_fill_discrete
Gradient colour scalesscale_color_date scale_color_datetime scale_color_gradient scale_color_gradient2 scale_color_gradientn scale_colour_date scale_colour_datetime scale_colour_gradient scale_colour_gradient2 scale_colour_gradientn scale_fill_date scale_fill_datetime scale_fill_gradient scale_fill_gradient2 scale_fill_gradientn
Sequential grey colour scalesscale_color_grey scale_colour_grey scale_fill_grey
Evenly spaced colours for discrete datascale_color_hue scale_colour_hue scale_fill_hue
Binned gradient colour scalesscale_color_steps scale_color_steps2 scale_color_stepsn scale_colour_steps scale_colour_steps2 scale_colour_stepsn scale_fill_steps scale_fill_steps2 scale_fill_stepsn
Viridis colour scales from viridisLitescale_color_ordinal scale_color_viridis_b scale_color_viridis_c scale_color_viridis_d scale_colour_ordinal scale_colour_viridis_b scale_colour_viridis_c scale_colour_viridis_d scale_fill_ordinal scale_fill_viridis_b scale_fill_viridis_c scale_fill_viridis_d
Position scales for continuous data (x & y)scale_x_continuous scale_x_log10 scale_x_reverse scale_x_sqrt scale_y_continuous scale_y_log10 scale_y_reverse scale_y_sqrt
Position scales for date/time datascale_x_date scale_x_datetime scale_x_time scale_y_date scale_y_datetime scale_y_time
Use values without scalingscale_alpha_identity scale_color_identity scale_colour_identity scale_continuous_identity scale_discrete_identity scale_fill_identity scale_linetype_identity scale_linewidth_identity scale_shape_identity scale_size_identity
Scale for line patternsscale_linetype scale_linetype_binned scale_linetype_continuous scale_linetype_discrete
Scales for line widthscale_linewidth scale_linewidth_binned scale_linewidth_continuous scale_linewidth_date scale_linewidth_datetime scale_linewidth_discrete scale_linewidth_ordinal
Create your own discrete scalescale_alpha_manual scale_color_manual scale_colour_manual scale_discrete_manual scale_fill_manual scale_linetype_manual scale_linewidth_manual scale_shape_manual scale_size_manual
Scales for shapes, aka glyphsscale_shape scale_shape_binned scale_shape_continuous scale_shape_discrete scale_shape_ordinal
Scales for area or radiusscale_radius scale_size scale_size_area scale_size_binned scale_size_binned_area scale_size_continuous scale_size_date scale_size_datetime scale_size_discrete scale_size_ordinal
Position scales for discrete datascale_x_discrete scale_y_discrete
Vector field of seal movementsseals
Specify a secondary axisderive dup_axis sec_axis
Compute empirical cumulative distributionstat_ecdf
Compute normal data ellipsesstat_ellipse
Leave data as isstat_identity
Extract coordinates from 'sf' objectsStatSfCoordinates stat_sf_coordinates
Bin and summarise in 2d (rectangle & hexagons)stat_summary2d stat_summary_2d stat_summary_hex
Summarise y values at unique/binned xstat_summary stat_summary_bin
Remove duplicatesstat_unique
Modify components of a themetheme
Housing sales in TXtxhousing
Quote faceting variablesvars