qplot | R Documentation |
Use qplot()
to draw simple ggplots. For example, you can draw a histogram
to visualize the distribution of a single variable (geom = "histogram"
).
You can draw a scatterplot to visualize the relationship between two
variables (geom = "point"
) and even add a line of best fit
(geom = c("point", "smooth")
). You can also represent a variable using
a different color
(and fill
, shape
, size
). Finally, you can facet
by a
discrete variable to draw multiple plots for each realization of that
variable.
qplot(x, y, ..., data, facets, geom, main)
x |
Specify which variable should be drawn on the x-axis. |
y |
Specify which variable should be drawn on the y-axis. If you're drawing the distribution of a single variable with a histogram or similar geom, specifying both x and y may be unnecessary. |
... |
Optionally include which variables should be represented
by |
data |
A data frame like a tibble. |
facets |
A faceting formula. For example, to facet by the
variable |
geom |
A character vector of geometries to draw. Any geom
from ggplot will work. For example, to use |
main |
A character string for the main plot title. |
ggplot()
, geom_histogram()
, geom_point()
, geom_smooth()
# A tibble with the heights and weights of 4 individuals: htwt <- tibble( sex = c("male", "male", "female", "female"), height = c(62, 72, 68, 64), weight = c(169, 243, 147, 135) ) # A simple scatterplot with sex represented by `color`: qplot( data = htwt, x = height, y = weight, color = sex, geom = "point", main = "Heights and Weights of 4 Individuals" ) ----------------------------------- # A simple histogram with sex represented by `fill`: qplot( data = htwt, x = height, fill = sex, geom = "histogram", bins = 4, main = "Frequency of Height Among 4 Individuals" ) ----------------------------------- # Faceting by sex: qplot( data = htwt, x = height, y = weight, color = sex, geom = c("point", "line"), facets = ~ sex, main = "Heights and Weights of 4 Individuals" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.