![]() ![]() ![]() # selecting subset of the data df_year <- dplyr :: filter ( gapminder :: gapminder, year = 2007 | year = 1957 ) # parametric t-test and box plot p1 <- ggbetweenstats ( data = df_year, x = year, y = lifeExp, xlab = "Year", ylab = "Life expectancy", plot.type = "box", type = "p", conf.level = 0.99, title = "Parametric test", package = "ggsci", palette = "nrc_npg" ) # Mann-Whitney U test (nonparametric t) and violin plot p2 <- ggbetweenstats ( data = df_year, x = year, y = lifeExp, xlab = "Year", ylab = "Life expectancy", plot.type = "violin", type = "np", conf.level = 0.99, title = "Non-parametric Test (violin plot)", package = "ggsci", palette = "uniform_startrek" ) # robust t-test and boxviolin plot p3 <- ggbetweenstats ( data = df_year, x = year, y = lifeExp, xlab = "Year", ylab = "Life expectancy", plot.type = "boxviolin", type = "r", conf.level = 0.99, title = "Robust Test (box & violin plot)", tr = 0.005, package = "wesanderson", palette = "Royal2", k = 3 ) # Bayes Factor for parametric t-test and boxviolin plot p4 <- ggbetweenstats ( data = df_year, x = year, y = lifeExp, xlab = "Year", ylab = "Life expectancy", type = "bayes", plot.type = "box", title = "Bayesian Test (box plot)", package = "ggsci", palette = "nrc_npg" ) # combining the individual plots into a single plot combine_plots ( list ( p1, p2, p3, p4 ), plotgrid.args = list (nrow = 2 ), annotation.args = list ( title = "Comparison of life expectancy between 19", caption = "Source: Gapminder Foundation" ) ) To make each plot have different colors or themes. It is possible, but not necessarily recommended, Then use combine_plots to merge them into one plot with We will generate the plots one by one and Let’sĬompare life expectancy for all countries for the first and last year ofĪvailable data 19. Let’s use the combine_plots function to make one plotįrom four separate plots that demonstrates all of these options. ![]() ![]() The type of plot to be displayed can also be modified The type (of test) argument also accepts theįollowing abbreviations: "p" (for parametric), Plot, but we can also use other available options: So far we have only used a classic parametric test and a boxviolin Possibly reflecting the war and the political turmoil. For example, although AsianĬountries are doing much better than African countries, on average,Īfghanistan has a particularly grim average for the Asian continent, Importantly, this plot also helps us appreciate theĭistributions within any given continent. Ggbetweenstats ( data = dplyr :: filter ( gapminder, year = 2007, continent != "Oceania" ), x = continent, # grouping/independent variable y = lifeExp, # dependent variables type = "robust", # type of statistics xlab = "Continent", # label for the x-axis ylab = "Life expectancy", # label for the y-axis plot.type = "boxviolin", # type of plot outlier.tagging = TRUE, # whether outliers should be flagged ef = 1.5, # coefficient for Tukey's rule outlier.label = country, # label to attach to outlier values = list (color = "red" ), # outlier point label color # turn off messages ggtheme = ggplot2 :: theme_gray ( ), # a different theme package = "yarrr", # package from which color palette is to be taken palette = "info2", # choosing a different color palette title = "Comparison of life expectancy across continents (Year: 2007)", caption = "Source: Gapminder Foundation" ) + # modifying the plot further ggplot2 :: scale_y_continuous ( limits = c ( 35, 85 ), breaks = seq (from = 35, to = 85, by = 5 ) )Īs can be appreciated from the effect size (partial eta squared) ofĠ.635, there are large differences in the mean life expectancy acrossĬontinents. We can and will change the overall theme as well X and y axis labels, and tag and label the Informative by making use of the many optional parameters in We can make the output much more aesthetically pleasing as well as Journal of Open Source Software, 6(61), 3167,Ī BibTeX entry for LaTeX users = ) =. Visualizations with statistical details: The To cite package 'ggstatsplot' in publications use: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |