R語言三大繪圖R包之三---ggstatsplot

美圖神器ggstatsplot-專為學術論文而生

在CRAN(comprehensive R Achive Netwokrk)中已有13000多個R包了
簡單講ggstatsplot能夠提供更為豐富信息的包,其實就是畫出高質量的圖
不需要我們花費過多的精力去調整繪圖細節(jié),舉個例子
一般的探索性數(shù)據(jù)分過程析包括數(shù)據(jù)可視化與數(shù)據(jù)統(tǒng)計兩個部分,而ggstatsplot正是達到兩者結合的目的

舉例說明

組間比較-ggbetweenstats

library(ggstatsplot)
library(ggplot2)

p代表參數(shù)檢驗,np代表非參數(shù)
mpaa是分類變量,y是數(shù)值型變量

head(movies_long)
## # A tibble: 6 x 8
##   title                        year length budget rating  votes mpaa  genre
##   <chr>                       <int>  <int>  <dbl>  <dbl>  <int> <fct> <fct>
## 1 Shawshank Redemption, The    1994    142     25    9.1 149494 R     Drama
## 2 Lord of the Rings: The Ret~  2003    251     94    9   103631 PG-13 Acti~
## 3 Lord of the Rings: The Fel~  2001    208     93    8.8 157608 PG-13 Acti~
## 4 Lord of the Rings: The Two~  2002    223     94    8.8 114797 PG-13 Acti~
## 5 Pulp Fiction                 1994    168      8    8.8 132745 R     Drama
## 6 Schindler's List             1993    195     25    8.8  97667 R     Drama
ggbetweenstats(
  data = movies_long,
  x = mpaa, # > 2 groups
  y = rating,
  type = "p", # default
  messages = FALSE
)

image

默認參數(shù)繪圖

ggbetweenstats(
  data = movies_long,
  x = mpaa,
  y = rating
)

image

配對比較
pairwise.display參數(shù)控制曾現(xiàn)的比較,ns無意義,all,所有,s有意義的

ggbetweenstats(
  data = movies_long,
  x = mpaa,
  y = rating,
  type = "np",
  mean.ci = TRUE,
  pairwise.comparisons = TRUE,
  pairwise.display = "s",
  p.adjust.method = "fdr",
  messages = FALSE
)

image

調整顏色,主題,可信區(qū)間調整,突出值標記
confi.level:可信區(qū)間調整,ggtheme主題,pallete:顏色調用
outlier:超出界限標記

ggbetweenstats(
  data = movies_long,
  x = mpaa,
  y = rating,
  type = "r",
  conf.level = 0.99,
  pairwise.comparisons = TRUE,
  pairwise.annotation = "p", 
  outlier.tagging = TRUE,
  outlier.label = title,
  outlier.coef = 2,
  ggtheme = hrbrthemes::theme_ipsum_tw(),
  palette = "Darjeeling2",
  package = "wesanderson",
  messages = FALSE
)

image

ggwithinstats組內比較

圖還是非常美觀,就不去細講每個參數(shù)了,需要時調用即可,這也是作者的意圖

ggwithinstats(
  data = WRS2::WineTasting,
  x = Wine, # > 2 groups
  y = Taste,
  pairwise.comparisons = TRUE,
  pairwise.annotation = "p",
  ggtheme = hrbrthemes::theme_ipsum_tw(),
  ggstatsplot.layer = FALSE,
  messages = FALSE
)

image

相關性圖-ggscatterstats

代碼簡介,細節(jié)豐富

ggscatterstats(
  data = movies_long,
  x = budget,
  y = rating,
  type = "p", # default #<<<
  conf.level = 0.99,
  marginal=F,
  messages = TRUE
)

image

其實還可以畫很多其它的圖,顏值都非常高,這里不再過多介紹,真正做到一圖勝千言

總結一下這個包的局限性:

  • 雖然圖的信息量大,但有時比如presentation,時間不夠,圖信息過多反而不利于簡明扼要的傳達信息
  • 另外就是計算的統(tǒng)計量比較單一

參考鏈接:http://www.itdecent.cn/p/bb3b4d5c2b15

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容