In a scatter plot, each row of data_frame is represented by a symbol
mark in 2D space.
Usage
px_scatter(
data_frame = NULL,
x = NULL,
y = NULL,
color = NULL,
symbol = NULL,
size = NULL,
hover_name = NULL,
hover_data = NULL,
custom_data = NULL,
text = NULL,
facet_row = NULL,
facet_col = NULL,
facet_col_wrap = 0,
facet_row_spacing = NULL,
facet_col_spacing = NULL,
error_x = NULL,
error_x_minus = NULL,
error_y = NULL,
error_y_minus = NULL,
animation_frame = NULL,
animation_group = NULL,
category_orders = NULL,
labels = NULL,
orientation = NULL,
color_discrete_sequence = NULL,
color_discrete_map = NULL,
color_continuous_scale = NULL,
range_color = NULL,
color_continuous_midpoint = NULL,
symbol_sequence = NULL,
symbol_map = NULL,
opacity = NULL,
size_max = NULL,
marginal_x = NULL,
marginal_y = NULL,
trendline = NULL,
trendline_options = NULL,
trendline_color_override = NULL,
trendline_scope = "trace",
log_x = FALSE,
log_y = FALSE,
range_x = NULL,
range_y = NULL,
render_mode = "auto",
title = NULL,
subtitle = NULL,
template = NULL,
width = NULL,
height = NULL
)Arguments
- data_frame
A data.frame, data.table, list or matrix. Needed for column names to be used in the other arguments; if
NULL, a data frame is built from the vectors given in the other arguments.- x
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to position marks along the x axis in cartesian coordinates.- y
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to position marks along the y axis in cartesian coordinates.- color
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign color to marks.- symbol
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign symbols to marks.- size
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign mark sizes.- hover_name
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector appear in bold in the hover tooltip.- hover_data
Extra data to show in the hover tooltip: column names (a character vector or a formula such as
~c(a, b)), or a named list with column names as names and valuesTRUE(default formatting),FALSE(hide the column, e.g. one shown by default), a d3-format string such as":.3f", a vector of data, or a list of a format string orTRUEand a vector of data.- custom_data
Column names (a character vector or a formula such as
~c(a, b)), or a list of column names, formulas and vectors. Values from these columns are added to the traces'customdata(e.g. for use in Shiny events) without appearing in the hover tooltip.- text
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector appear in the figure as text labels.- facet_row
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign marks to facetted subplots in the vertical direction.- facet_col
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign marks to facetted subplots in the horizontal direction.- facet_col_wrap
Maximum number of facet columns. Wraps the column variable at this width, so that the column facets span multiple rows. Ignored if 0, and forced to 0 if
facet_rowor amarginalis set.- facet_row_spacing
Spacing between facet rows, in paper units. Default is 0.03 or 0.07 when facet_col_wrap is used.
- facet_col_spacing
Spacing between facet columns, in paper units Default is 0.02.
- error_x
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to size x-axis error bars. Iferror_x_minusisNULL, error bars will be symmetrical, otherwiseerror_xis used for the positive direction only.- error_x_minus
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to size x-axis error bars in the negative direction. Ignored iferror_xisNULL.- error_y
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to size y-axis error bars. Iferror_y_minusisNULL, error bars will be symmetrical, otherwiseerror_yis used for the positive direction only.- error_y_minus
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to size y-axis error bars in the negative direction. Ignored iferror_yisNULL.- animation_frame
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to assign marks to animation frames.- animation_group
A column name in
data_frame, a vector of values, a one-sided formula evaluated indata_frame(e.g.~ log(pop)),px_constant()orpx_range(). Values from this column or vector are used to provide object-constancy across animation frames: rows with matchinganimation_groups will be treated as if they describe the same object in each frame.- category_orders
Named list mapping column names to the order of their values in axes, legends and facets, e.g.
list(day = c("Thur", "Fri", "Sat", "Sun")). By default values appear in the order first encountered, or in level order for factors.- labels
Named character vector or list mapping column names to the labels to use for axis titles, legend entries and hover text, e.g.
c(gdpPercap = "GDP per capita").- orientation
(default
"v"ifxandyare provided and both continuous or both categorical, otherwise"v"("h") ifx(y) is categorical andy(x) is continuous, otherwise"v"("h") if onlyx(y) is provided)- color_discrete_sequence
Character vector of colors, e.g.
px_colors$qualitative$Set1. Values ofcolorare assigned colors in order (cycling), unless set incolor_discrete_map. Defaults to the template'scolorway.- color_discrete_map
Named character vector or list mapping values of
colorto colors, overridingcolor_discrete_sequence. If the values ofcolorare colors,px_identity()(or"identity") uses them directly.- color_continuous_scale
Character vector of colors, e.g.
px_colors$sequential$Viridis, or the name of a scale in px_colors. Used whencoloris numeric. Defaults to the template's sequential colorscale.- range_color
If provided, overrides auto-scaling on the continuous color scale.
- color_continuous_midpoint
If set, computes the bounds of the continuous color scale to have the desired midpoint. Setting this value is recommended when using
plotly.express.colors.divergingcolor scales as the inputs tocolor_continuous_scale.- symbol_sequence
Strings should define valid plotly.js symbols. When
symbolis set, values in that column are assigned symbols by cycling throughsymbol_sequencein the order described incategory_orders, unless the value ofsymbolis a key insymbol_map.- symbol_map
Named character vector or list mapping values of
symbolto marker symbols, overridingsymbol_sequence.px_identity()uses the values ofsymboldirectly.- opacity
Value between 0 and 1. Sets the opacity for markers.
- size_max
Set the maximum mark size when using
size.- marginal_x
One of
"rug","box","violin", or"histogram". If set, a horizontal subplot is drawn above the main plot, visualizing the x-distribution.- marginal_y
One of
"rug","box","violin", or"histogram". If set, a vertical subplot is drawn to the right of the main plot, visualizing the y-distribution.- trendline
One of
"ols"(ordinary least squares regression),"lowess"(locally weighted smoothing),"rolling","expanding"or"ewm"(exponentially weighted moving average). A trendline is drawn for each discrete color/symbol group; configure it withtrendline_options. Fitted OLS models are available frompx_get_trendline_results().- trendline_options
Named list of options for the trendline function: for
"ols",add_constant,log_xandlog_y; for"lowess",frac; for"rolling",window,min_periods,centerandfunction("mean","median","sum","min","max","std","var","count"); for"expanding",min_periodsandfunction; for"ewm", one ofcom,span,halflifeoralpha, andadjust.- trendline_color_override
Valid CSS color. If provided, and if
trendlineis set, all trendlines will be drawn in this color rather than in the same color as the traces from which they draw their inputs.- trendline_scope
If
"trace", then one trendline is drawn per trace (i.e. per color, symbol, facet, animation frame etc) and if"overall"then one trendline is computed for the entire dataset, and replicated across all facets.- log_x
If
TRUE, the x-axis is log-scaled in cartesian coordinates.- log_y
If
TRUE, the y-axis is log-scaled in cartesian coordinates.- range_x
If provided, overrides auto-scaling on the x-axis in cartesian coordinates.
- range_y
If provided, overrides auto-scaling on the y-axis in cartesian coordinates.
- render_mode
One of
"auto","svg"or"webgl", default"auto"Controls the browser API used to draw marks."svg"is appropriate for figures of less than 1000 data points, and will allow for fully-vectorized output."webgl"is likely necessary for acceptable performance above 1000 points but rasterizes part of the output."auto"uses heuristics to choose the mode.- title
The figure title.
- subtitle
The figure subtitle.
- template
A template name (see
template_names()) or a template list. Defaults todefault_template().- width
The figure width in pixels.
- height
The figure height in pixels.
Value
A go_figure().
See also
Other plotly express:
px_area(),
px_bar(),
px_bar_polar(),
px_box(),
px_choropleth(),
px_choropleth_map(),
px_density_contour(),
px_density_heatmap(),
px_density_map(),
px_ecdf(),
px_funnel(),
px_funnel_area(),
px_histogram(),
px_icicle(),
px_imshow(),
px_line(),
px_line_3d(),
px_line_geo(),
px_line_map(),
px_line_polar(),
px_line_ternary(),
px_parallel_categories(),
px_parallel_coordinates(),
px_pie(),
px_scatter_3d(),
px_scatter_geo(),
px_scatter_map(),
px_scatter_matrix(),
px_scatter_polar(),
px_scatter_ternary(),
px_strip(),
px_sunburst(),
px_timeline(),
px_treemap(),
px_violin()
Examples
px_data_iris() |>
px_scatter(x = ~sepal_width, y = ~sepal_length, color = ~species,
size = ~petal_length, hover_data = ~petal_width)
px_data_tips() |> px_scatter(x = ~total_bill, y = ~tip, facet_col = ~time, trendline = "ols")