當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。