Boxplots and Grouped Boxplots in R | R Tutorial 2.2 | MarinStatsLectures



Boxplots and Grouped Boxplots in R: How to Create and Modify Boxplots and Group Boxplots (Side By Side Box plots) with R; Link to Free Dataset: ( Box plots Explained in this video: ( 👍🏼Best Statistics & R Programming Tutorials: ( )

►► Like to support us? You can Donate ( Share our Videos, Leave us a Comment and Give us a Thumbs up! Either way We Thank You!

In this R video tutorial, we will learn how to produce box plots (a.k.a. box and whisker diagram) in R, as well as “side by side boxplots” for multiple groups (i.e. boxplots with groups) with examples. In this R tutorial we will also learn how to add titles, change axes labels, and many other modifications to the plot by using “boxplot”, “~”, “ylim”, and “quantile” functions and “xlab”, “ylab”, “ylim”, “las” arguments.

► ►You can access and download the “LungCapData” dataset here:

◼︎ Table of Content:

► 0:00:05 what is a box plot and when should we use it
► 0:00:25 how to produce a “box plot” in R? By using “box.plot” function
► 0:00:30 how to access the help menu in R
► 0:00:56 how to report the “minimum”, “first quartile”, “median”, “third quartile”, and “maximum” in a “box plot” in R? By using the “quantile” function

► ► Modifying Box Plots in R

► 0:01:31 how to add a title to a boxplot in R using the “main” argument
► 0:01:39 how to label the x-axis or the y-axis of a “box plot” using “xlab” or “ylab” arguments
► 0:01:52 how to change the limits for the y-axis of a “box plot” in R using the “ylim” argument
► 0:02:04 how to rotate the values on the y-axis of a “box plot” using “las” argument
► 0:02:13 how to produce side-by-side box plots in R using “boxplot” and “~” (separate) functions (for example: when comparing the distribution of a numeric variable for different groups that are formed by a categorical variable)
► 0:02:53 how to add a title to side-by-side boxplots in R using the “main” argument
► 0:03:04 how to produce side-by-side box plots in R using the “square brackets” to subset data
► 0:03:35 double equal sign (==) , what does this mean?

These video tutorials are useful for anyone interested in learning data science and statistics with R programming language using RStudio.

►► Watch More:

► Intro to Statistics Course:
►R Tutorials for Data Science
►Getting Started with R (Series 1):
►Graphs and Descriptive Statistics in R (Series 2):
►Probability distributions in R (Series 3):
►Bivariate analysis in R (Series 4):
►Linear Regression in R (Series 5):
►ANOVA Concept and with R
►Linear Regression Concept and with R

Follow MarinStatsLectures

Subscribe:
website:
Facebook:
Twitter:
Instagram:

Our Team:
Content Creator: Mike Marin (B.Sc., MSc.) Senior Instructor at UBC.
Producer and Creative Manager: Ladan Hamadani (B.Sc., BA., MPH)

These videos are created by #marinstatslectures to support some courses at The University of British Columbia (UBC) (#IntroductoryStatistics and #RVideoTutorials for Health Science Research), although we make all videos available to the everyone everywhere for free.

Thanks for watching! Have fun and remember that statistics is almost as beautiful as a unicorn!

source

31 Comments

  1. In this R video tutorial you will learn how to produce box plots (or box and whisker diagram), as well as "side by side boxplots" for multiple groups (i.e. boxplots with groups) in R. Here we will learn how to add titles, change axes labels, and many other modifications to the plot by using different functions and arguments In R. Like to support us? You can Donate https://statslectures.com/support-us or Share the Videos. Make sure to donwload the Free LungCapData here for Practice : ( https://bit.ly/2rOfgEJ )

  2. I need to make 2 box plots. 1 with systolic blood pressure for obesity, 1 for systolic blood pressure without obesity. I have no idea how to determine obesity with bmi of 30 or more. HELP ME

  3. I did not know what a tilde operator (~) was in R. It made me lose 2 hours trying to understand what was wrong. The help file for this function does not explain it!!! R is the most infuriating language I have encountered.

  4. Question: I am to create boxplot from log10 of my dataset using ggplot in R. Log10 values of my data contains -ve and +ve infinitive values. In addition, 1st quartilex, min and median for some variables show infinitive values after log-transformation. But on the boxplot only 0-3 values can be seen. What about the infinitives?

  5. Hey,
    I am strictly following your instruction which I find genial, yet I have the following problem this time. It seem to be unsolvable for me:
    1) I write down the command line as follows in your video:
    > LungCapData <- read.table(file.choose(), header = T, sep = "t")
    Then I choose the txt file from my Mac (LungCapData).

    When I write the attach command, I get this notification
    > attach(LungCapData)

    The following object is masked by .GlobalEnv:

    LungCap

    The following objects are masked from LungCapData (pos = 4):

    Age, Caesarean, Gender, Height, LungCap, Smoke

    The following objects are masked from LungCapData (pos = 5):

    Age, Caesarean, Gender, Height, LungCap, Smoke

    The following objects are masked from LungCapData (pos = 6):

    Age, Caesarean, Gender, Height, LungCap, Smoke

    The following objects are masked from LungCapData (pos = 7):

    Age, Caesarean, Gender, Height, LungCap, Smoke

    Then I do the classification:
    class(LungCap) "numeric"
    !!! the Gender classification looks as follows though:
    class("Gender")
    "character"

    So, when I am trying to build the Boxplot, I get the following error all the time:
    > boxplot(LungCap)
    Fehler in plot.new() : figure margins too large.

    2) The command > LungCapData <- read.table(file.choose(), header = T, sep = "t") didn't work for csv as well

    > LungCapData <- read.table(file.choose(), header = T, sep = "t")

    > attach(LungCapData)

    The following object is masked from LungCapData (pos = 6):

    LungCap.Age.Height.Smoke.Gender.Caesarean

    > class(LungCap)
    [1] "numeric"
    > class(Gender)
    [1] "factor"
    > class(Age)
    [1] "integer"
    > class(Height)
    [1] "factor"
    > class(Smoke)
    [1] "factor"
    > class(Caesarean)
    [1] "factor"

    > boxplot(LungCap)
    Fehler in plot.new() : figure margins too large

    3) For xlsx: I managed to get the boxplot, yet the lines look very strange to me:

    LungCapData <- read_excel("Desktop/study abroad/Online education/R beginning/LungCapData.xlsx",
    + col_types = c("numeric", "numeric", "numeric",
    + "text", "text", "text"))

    > View(LungCapData)

    > attach(LungCapData)

    The following object is masked by .GlobalEnv:

    LungCap

    The following objects are masked from LungCapData (pos = 5):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 6):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 7):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 9):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 10):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 11):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    The following objects are masked from LungCapData (pos = 12):

    Age, Caesarean, Gender, Height, LungCap,
    Smoke

    > class(LungCap)
    [1] "numeric"

    > class(Gender)
    [1] "character"
    > class(Smoke)
    [1] "character"

    > boxplot(LungCap)

    Many thanks and cheers,

Leave a Reply

Your email address will not be published. Required fields are marked *

You might like

© 2026 Cantinho do Vídeo - WordPress Video Theme by WPEnjoy