qplot

0th

Percentile

Quick plot

qplot is the basic plotting function in the ggplot2 package, designed to be familiar if you're used to plot from the base package. It is a convenient wrapper for creating a number of different types of plots using a consistent calling scheme. See http://had.co.nz/ggplot2/book/qplot.pdf for the chapter in the ggplot2 book which describes the usage of qplot in detail.

Usage
qplot(x, y = NULL, ..., data, facets = NULL,
    margins = FALSE, geom = "auto", stat = list(NULL),
    position = list(NULL), xlim = c(NA, NA),
    ylim = c(NA, NA), log = "", main = NULL,
    xlab = deparse(substitute(x)),
    ylab = deparse(substitute(y)), asp = NA)
Arguments
x
x values
y
y values
...
other aesthetics passed for each layer
data
data frame to use (optional). If not specified, will create one, extracting vectors from the current environment.
facets
faceting formula to use. Picks facet_wrap or facet_grid depending on whether the formula is one sided or two-sided
margins
whether or not margins will be displayed
geom
character vector specifying geom to use. Defaults to "point" if x and y are specified, and "histogram" if only x is specified.
stat
character vector specifying statistics to use
position
character vector giving position adjustment to use
xlim
limits for x axis
ylim
limits for y axis
log
which variables to log transform ("x", "y", or "xy")
main
character vector or expression for plot title
xlab
character vector or expression for x axis label
ylab
character vector or expression for y axis label
asp
the y/x aspect ratio
Aliases
  • qplot
  • quickplot
Examples
# Use data from data.frame
qplot(mpg, wt, data=mtcars)
qplot(mpg, wt, data=mtcars, colour=cyl)
qplot(mpg, wt, data=mtcars, size=cyl)
qplot(mpg, wt, data=mtcars, facets=vs ~ am)

# It will use data from local environment
hp <- mtcars$hp
wt <- mtcars$wt
cyl <- mtcars$cyl
vs <- mtcars$vs
am <- mtcars$am
qplot(hp, wt)
qplot(hp, wt, colour=cyl)
qplot(hp, wt, size=cyl)
qplot(hp, wt, facets=vs ~ am)

qplot(1:10, rnorm(10), colour = runif(10))
qplot(1:10, letters[1:10])
mod <- lm(mpg ~ wt, data=mtcars)
qplot(resid(mod), fitted(mod))
qplot(resid(mod), fitted(mod), facets = . ~ vs)

f <- function() {
   a <- 1:10
   b <- a ^ 2
   qplot(a, b)
}
f()

# qplot will attempt to guess what geom you want depending on the input
# both x and y supplied = scatterplot
qplot(mpg, wt, data = mtcars)
# just x supplied = histogram
qplot(mpg, data = mtcars)
# just y supplied = scatterplot, with x = seq_along(y)
qplot(y = mpg, data = mtcars)

# Use different geoms
qplot(mpg, wt, data = mtcars, geom="path")
qplot(factor(cyl), wt, data = mtcars, geom=c("boxplot", "jitter"))
Documentation reproduced from package ggplot2, version 0.9.3.1, License: GPL-2

Community examples

torjaialexa@gmail.com at May 1, 2019 ggplot2 v3.1.1

funkcia = function(a,b,n){ for(i in 1:n){ if(i<a){ print(i/4) } else if ((i==a)||((i>a)&&(i<b))){ print(i/3) } else if ((i==b)||((i>b)&&(i<n))){ print(i/2) } }} funkcia(5,8,15) set.seed(18) tabulka= data.table(A=15:1,B=rep(c("b","a","c"),each=5),D=15:1,C=rnorm(15)) tabulka tabulka$C[c(7,8)]=NA summary(tabulka) sum(is.na(tabulka$C)) all(tabulka$D>0) sort(tabulka$C) tabulka[,E:=sum(D),by=B] tabulka[,F:=A^3] tabulka library(base) quakes=quakes par(mfrow=c(1,2)) with(quakes, plot(long,depth,col="green",main = "vlavo")) with(quakes, plot(lat,depth,col="blue",main = "vpravo")) library(ggplot2) qplot(lat,stations,data=quakes,col=mag)