{ggplot2} R# Documentation

ggplot2


require(ggplot);

#' Create Elegant Data Visualisations Using the Grammar of Graphics
imports "ggplot2" from "ggplot";

Create Elegant Data Visualisations Using the Grammar of Graphics



.NET clr function exports
ggplot

Create a new ggplot

ggplot() initializes a ggplot object. It can be used to declare the input data frame for a graphic and to specify the set of plot aesthetics intended to be common throughout all subsequent layers unless specifically overridden.

aes

Construct aesthetic mappings

Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in ggplot() and in individual layers.

geom_point

Scatter Points

The point geom is used to create scatterplots. The scatterplot is most useful for displaying the relationship between two continuous variables. It can be used to compare one continuous and one categorical variable, or two categorical variables, but a variation like geom_jitter(), geomcount(), or geombin2d() is usually more appropriate. A bubblechart is a scatterplot with a third variable mapped to the size of points.

geom_text

Text

Text geoms are useful for labeling plots. They can be used by themselves as scatterplots or in combination with other geoms, for example, for labeling points or for annotating the height of bars. geom_text() adds only text to the plot. geom_label() draws a rectangle behind the text, making it easier to read.

geom_histogram

Histograms and frequency polygons

Visualise the distribution of a single continuous variable by dividing the x axis into bins and counting the number of observations in each bin. Histograms (geom_histogram()) display the counts with bars;

geom_line

Connect observations

geom_path() connects the observations in the order in which they appear in the data. geom_line() connects them in order of the variable on the x axis. geom_step() creates a stairstep plot, highlighting exactly when changes occur. The group aesthetic determines which cases are connected together.

geom_hline

Reference line defined by Y intercept. Useful for annotating plots.

Using the described geometry, you can insert a simple geometric object into your data visualization – a line defined by a position on the Y axis.

geom_vline

Reference lines: horizontal, vertical, and diagonal

These geoms add reference lines (sometimes called rules) to a plot, either horizontal, vertical, or diagonal (specified by slope and intercept). These are useful for annotating plots.

geom_path

Connect observations

geom_path() connects the observations in the order in which they appear in the data. geom_line() connects them in order of the variable on the x axis. geom_step() creates a stairstep plot, highlighting exactly when changes occur. The group aesthetic determines which cases are connected together.

geom_convexHull
geom_boxplot

A box and whiskers plot (in the style of Tukey)

The boxplot compactly displays the distribution of a continuous variable. It visualises five summary statistics (the median, two hinges and two whiskers), and all "outlying" points individually.

geom_col

Bar charts

There are two types of bar charts: geombar() and geomcol(). geom_bar() makes the height of the bar proportional to the number of cases in each group (or if the weight aesthetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use geomcol() instead. geombar() uses stat_count() by default: it counts the number of cases at each x position. geomcol() uses statidentity(): it leaves the data as is.

geom_bar

Bar charts

There are two types of bar charts: geombar() and geomcol(). geom_bar() makes the height of the bar proportional to the number of cases in each group (or if the weight aesthetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use geomcol() instead. geombar() uses stat_count() by default: it counts the number of cases at each x position. geomcol() uses statidentity(): it leaves the data as is.

geom_barplot
geom_violin
geom_jitter
geom_scatterpie
geom_scatterheatmap
geom_pie
geom_raster
geom_tile
annotation_raster

annotation_raster: Annotation: high-performance rectangular tiling This is a special version of geom_raster() optimised for static annotations that are the same in every panel. These annotations will not affect scales (i.e. the x and y axes will not grow to cover the range of the raster, and the raster must already have its own colours). This is useful for adding bitmap images.

labs

Modify axis, legend, and plot labels

Good labels are critical for making your plots accessible to a wider audience. Always ensure the axis and legend labels display the full variable name. Use the plot title and subtitle to explain the main findings. It's common to use the caption to provide information about the data source. tag can be used for adding identification tags to differentiate between multiple plots.

stat_pvalue_manual

set stats p-value for the plot

stat_compare_means

default create anova test for compares all groups

geom_signif

Create significance layer

xlab

Modify axis, legend, and plot labels

Good labels are critical for making your plots accessible to a wider audience. Always ensure the axis and legend labels display the full variable name. Use the plot title and subtitle to explain the main findings. It's common to use the caption to provide information about the data source. tag can be used for adding identification tags to differentiate between multiple plots.

ylab

Modify axis, legend, and plot labels

Good labels are critical for making your plots accessible to a wider audience. Always ensure the axis and legend labels display the full variable name. Use the plot title and subtitle to explain the main findings. It's common to use the caption to provide information about the data source. tag can be used for adding identification tags to differentiate between multiple plots.

coord_flip

Swapping X- and Y-Axes

theme

Modify components of a theme

Themes are a powerful way to customize the non-data components of your plots: i.e. titles, labels, fonts, background, gridlines, and legends. Themes can be used to give plots a consistent customized look. Modify a single plot's theme using theme(); see theme_update() if you want modify the active theme, to affect all subsequent plots. Use the themes available in complete themes if you would like to use a complete theme such as themebw(), thememinimal(), and more. Theme elements are documented together according to inheritance, read more about theme inheritance below.

element_blank

means nothing

waiver

A waiver object.

A waiver is a "flag" object, similar to NULL, that indicates the calling function should just use the default value. It is used in certain functions to distinguish between displaying nothing (NULL) and displaying a default value calculated elsewhere (waiver())

element_line

Theme element: line.

ggtitle

Modify axis, legend, and plot labels

Good labels are critical for making your plots accessible to a wider audience. Always ensure the axis and legend labels display the full variable name. Use the plot title and subtitle to explain the main findings. It's common to use the caption to provide information about the data source. tag can be used for adding identification tags to differentiate between multiple plots.

scale_colour_manual

Create your own discrete scale

These functions allow you to specify your own set of mappings from levels in the data to aesthetic values.

scale_color_brewer

Sequential, diverging and qualitative colour scales from ColorBrewer

scale_fill_manual
scale_fill_distiller
scale_x_continuous

Position scales for continuous data (x & y)

scale_y_continuous

Position scales for continuous data (x & y)

scale_y_reverse

Position scales for continuous data (x & y)

element_text

Theme elements

text.

element_rect

Theme elements

In conjunction with the theme system, the element_ functions specify the display of how non-data components of the plot are drawn. borders and backgrounds.


[Document Index]