当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R ggplot2 qplot 快速情节


qplot() 现已弃用,以鼓励用户学习 ggplot(),因为它可以更轻松地创建复杂图形。

用法

qplot(
  x,
  y,
  ...,
  data,
  facets = NULL,
  margins = FALSE,
  geom = "auto",
  xlim = c(NA, NA),
  ylim = c(NA, NA),
  log = "",
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  asp = NA,
  stat = deprecated(),
  position = deprecated()
)

quickplot(
  x,
  y,
  ...,
  data,
  facets = NULL,
  margins = FALSE,
  geom = "auto",
  xlim = c(NA, NA),
  ylim = c(NA, NA),
  log = "",
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  asp = NA,
  stat = deprecated(),
  position = deprecated()
)

参数

x, y, ...

美学渗透到每一层

data

要使用的 DataFrame (可选)。如果未指定,将创建一个,从当前环境中提取向量。

facets

要使用的分面公式。根据公式是单面还是双面选择 facet_wrap()facet_grid()

margins

请参阅facet_grid():显示边面?

geom

指定要绘制的几何图形的字符向量。如果指定了 x 和 y,则默认为"point";如果仅指定了 x,则默认为"histogram"。

xlim, ylim

X 轴和 y 轴限制

log

要记录哪些变量转换("x"、"y" 或 "xy")

main, xlab, ylab

分别给出绘图标题、x 轴标签和 y 轴标签的字符向量(或表达式)。

asp

y/x 纵横比

stat, position

[Deprecated]

例子

# Use data from data.frame
qplot(mpg, wt, data = mtcars)
#> Warning: `qplot()` was deprecated in ggplot2 3.4.0.

qplot(mpg, wt, data = mtcars, colour = cyl)

qplot(mpg, wt, data = mtcars, size = cyl)

qplot(mpg, wt, data = mtcars, facets = vs ~ am)


# \donttest{
set.seed(1)
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))


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


# To set aesthetics, wrap in I()
qplot(mpg, wt, data = mtcars, colour = I("red"))


# 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)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# 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"))

qplot(mpg, data = mtcars, geom = "dotplot")
#> Bin width defaults to 1/30 of the range of the data. Pick better value
#> with `binwidth`.

# }
源代码:R/quick-plot.R

相关用法


注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Quick plot。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。