最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

R語言利用ggplot2繪制QQ圖和箱線圖詳解

 更新時間:2022年06月09日 14:12:32   作者:zoujiahui_2018  
這篇文章主要為大家介紹了R語言如何利用ggplot2繪制QQ圖和箱線圖,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)R語言有一定的幫助,需要的可以參考一下

繪制qq圖

在ggplot2中繪制qq圖需要兩步,geom_qq()將繪制樣本分位點(diǎn),geom_qq_line()將繪制標(biāo)準(zhǔn)正態(tài)線

函數(shù)介紹

geom_qq()

geom_qq(
  mapping = NULL,
  data = NULL,
  geom = "point",
  position = "identity",
  ...,
  distribution = stats::qnorm,
  dparams = list(),
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)
geom_qq_line(
  mapping = NULL,
  data = NULL,
  geom = "path",
  position = "identity",
  ...,
  distribution = stats::qnorm,
  dparams = list(),
  line.p = c(0.25, 0.75),
  fullrange = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

參數(shù)介紹

**aes()**中的映射參數(shù)必須包含sample,可選參數(shù)有g(shù)roup,x,y distribution

Distribution function to use, if x not specified
dparams Additional parameters passed on to distribution function.
line.p Vector of quantiles to use when fitting the Q-Q line, defaults defaults to c(.25, .75).
fullrange Should the q-q line span the full range of the plot, or just the data

注意事項(xiàng)

**aes()**中的映射參數(shù)必須包含sample

例子

Using to explore the distribution of a variable

ggplot(mtcars, aes(sample = mpg)) +
  stat_qq() +
  stat_qq_line()
ggplot(mtcars, aes(sample = mpg, colour = factor(cyl))) +
  stat_qq() +
  stat_qq_line()

繪制boxplot

函數(shù)介紹

geom_boxplot(
  mapping = NULL,
  data = NULL,
  stat = "boxplot",
  position = "dodge2",
  ...,
  outlier.colour = NULL,
  outlier.color = NULL,
  outlier.fill = NULL,
  outlier.shape = 19,
  outlier.size = 1.5,
  outlier.stroke = 0.5,
  outlier.alpha = NULL,
  notch = FALSE,
  notchwidth = 0.5,
  varwidth = FALSE,
  na.rm = FALSE,
  orientation = NA,
  show.legend = NA,
  inherit.aes = TRUE
)

參數(shù)介紹

aes()可接收的參數(shù)有:

  • x or y, 利用x將會是橫向箱線圖,y的是縱向
  • lower or xlower
  • upper or xupper
  • middle or xmiddle
  • ymin or xmin
  • ymax or xmax
  • alpha
  • colour
  • fill
  • group
  • linetype
  • shape
  • size
  • weight

notch If FALSE (default) make a standard box plot. If TRUE, make a notched box plot. Notches are used to compare groups; if the notches
of two boxes do not overlap, this suggests that the medians are
significantly different.
notchwidth For a notched box plot, width of the notch relative to the body (defaults to notchwidth = 0.5).
varwidth If FALSE (default) make a standard box plot. If TRUE, boxes are drawn with widths proportional to the square-roots of the
number of observations in the groups (possibly weighted, using the
weight aesthetic).

例子

p <- ggplot(mpg, aes(x=class, y=hwy))
p + geom_boxplot()

ggplot(mpg, aes(x=hwy, y=class)) + geom_boxplot()

p <- ggplot(mpg, aes(x=class, y=hwy))
p + geom_boxplot(notch = TRUE,varwidth = TRUE,fill = "white", colour = "#3366FF")

ggplot(diamonds, aes(carat, price)) +
  geom_boxplot(aes(group = cut_width(carat, 0.25)))

p <- ggplot(mpg, aes(x=class, y=hwy))
p + geom_boxplot(outlier.shape = NA) + geom_jitter(width = 0.2)

利用分位點(diǎn)繪制箱線圖

y <- rnorm(100)
df <- data.frame(
  x = 1,
  y0 = min(y),
  y25 = quantile(y, 0.25),
  y50 = median(y),
  y75 = quantile(y, 0.75),
  y100 = max(y)
)
ggplot(df, aes(x)) +
  geom_boxplot(
    aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100),
    stat = "identity"
  )

將QQ圖和箱線圖進(jìn)行融合

函數(shù)介紹

該函數(shù)是來自于qqboxplot包,因此使用前需要安裝

geom_qqboxplot(
  mapping = NULL,
  data = NULL,
  stat = "qqboxplot",
  position = "dodge2",
  ...,
  outlier.colour = NULL,
  outlier.color = NULL,
  outlier.fill = NULL,
  outlier.shape = 19,
  outlier.size = 1.5,
  outlier.stroke = 0.5,
  outlier.alpha = NULL,
  notch = FALSE,
  notchwidth = 0.5,
  varwidth = FALSE,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

參數(shù)介紹

大部分參數(shù)和geom_qq()和geom_boxplot()中的參數(shù)含義相同

reference_dist 表示參數(shù)比較的標(biāo)準(zhǔn)分布名稱,如果有參數(shù)需要有dparams

compdata 用于比較的標(biāo)準(zhǔn)樣本數(shù)據(jù),是個向量

注意事項(xiàng)

aes()函數(shù)中的y不可缺

例子

library(dplyr)
library(ggplot2)
library(qqboxplot)

simulated_data=tibble(y=c(rnorm(1000, mean=2), rt(1000, 16), rt(500, 4), 
                          rt(1000, 8), rt(1000, 32)),
                      group=c(rep("normal, mean=2", 1000), 
                              rep("t distribution, df=16", 1000), 
                              rep("t distribution, df=4", 500), 
                              rep("t distribution, df=8", 1000), 
                              rep("t distribution, df=32", 1000)))
p <- ggplot2::ggplot(simulated_data, ggplot2::aes(factor(group,
                                                         levels=c("normal, mean=2", "t distribution, df=32", "t distribution, df=16",
                                                                  "t distribution, df=8", "t distribution, df=4")), y=y))
p + geom_qqboxplot()
p + geom_qqboxplot(reference_dist = "norm")


p + geom_qqboxplot(compdata = comparison_dataset)

以上就是R語言利用ggplot2繪制QQ圖和箱線圖詳解的詳細(xì)內(nèi)容,更多關(guān)于R語言繪制QQ圖 箱線圖的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 使用ggsignif優(yōu)雅添加顯著性標(biāo)記詳解

    使用ggsignif優(yōu)雅添加顯著性標(biāo)記詳解

    這篇文章主要為大家介紹了使用ggsignif優(yōu)雅添加顯著性標(biāo)記詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • R語言的特點(diǎn)總結(jié)

    R語言的特點(diǎn)總結(jié)

    在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于R語言的特點(diǎn)總結(jié)內(nèi)容,有需要的朋友們可以學(xué)習(xí)參考下。
    2021-03-03
  • R語言的下載安裝圖文教程講解

    R語言的下載安裝圖文教程講解

    這篇文章主要介紹了R語言的下載安裝圖文教程講解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • R語言中向量的加法和乘法運(yùn)算

    R語言中向量的加法和乘法運(yùn)算

    這篇文章主要介紹了R語言中向量的加法和乘法運(yùn)算,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • R語言實(shí)現(xiàn)地理加權(quán)回歸(GWR)

    R語言實(shí)現(xiàn)地理加權(quán)回歸(GWR)

    這篇文章主要為大家介紹了R語言實(shí)現(xiàn)地理加權(quán)回歸(GWR)操作流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • R語言可視化ggplot2繪制24小時動態(tài)血糖圖

    R語言可視化ggplot2繪制24小時動態(tài)血糖圖

    這篇文章主要為大家介紹了R語言可視化使用ggplot2繪制24小時動態(tài)血糖,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • R語言如何實(shí)現(xiàn)多元線性回歸

    R語言如何實(shí)現(xiàn)多元線性回歸

    這篇文章主要給大家介紹了關(guān)于R語言如何實(shí)現(xiàn)多元線性回歸的相關(guān)資料,文中介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • R語言中循環(huán)的相關(guān)知識詳解

    R語言中循環(huán)的相關(guān)知識詳解

    這篇文章主要為大家詳細(xì)介紹了R語言中循環(huán)的相關(guān)知識,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)R語言有一定的幫助,感興趣的可以了解一下
    2023-03-03
  • R語言實(shí)現(xiàn)ggplot重繪天貓雙十一銷售額曲線圖過程

    R語言實(shí)現(xiàn)ggplot重繪天貓雙十一銷售額曲線圖過程

    這篇文章主要為大家介紹了如何使用ggplot繪制天貓雙十一銷售額曲線圖的實(shí)現(xiàn)過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2021-11-11
  • R語言繪圖-點(diǎn)圖dot plot

    R語言繪圖-點(diǎn)圖dot plot

    這篇文章主要介紹了R語言繪圖-點(diǎn)圖dot plot案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04

最新評論

尖扎县| 赤峰市| 多伦县| 建昌县| 肃南| 宣威市| 永康市| 西畴县| 嵩明县| 收藏| 平舆县| 古蔺县| 武胜县| 姚安县| 新竹市| 光泽县| 林州市| 上饶县| 津市市| 卫辉市| 滕州市| 荆门市| 分宜县| 寻乌县| 交口县| 陇西县| 察隅县| 昭通市| 龙陵县| 德昌县| 文登市| 高阳县| 田东县| 邓州市| 江都市| 策勒县| 岳西县| 三江| 宝兴县| 灯塔市| 白银市|