Boxplot in R (9 Examples) | Create a Box-and-Whisker Plot in RStudio | boxplot() Function & ggplot2

preview_player
Показать описание
R code of this video tutorial:

##### Example 1
x <- rnorm(1000)
boxplot(x) # Basic boxplot in R

##### Example 2
y <- runif(1000) # Create more variables
z <- rpois(1000, 3)
group = c(rep("x", 1000),
rep("y", 1000),
rep("z", 1000)))
head(data) # First six rows of data
boxplot(values ~ group, data) # Multiple boxplots in same graph

##### Example 3
boxplot(values ~ group, data, # Change main title and axis labels
main = "My Boxplots",
xlab = "My Boxplot Groups",
ylab = "The Values of My Boxplots")

##### Example 4
boxplot(values ~ group, data, # Horizontal boxplots
horizontal = TRUE)

##### Example 5
boxplot(values ~ group, data, # Thin boxplots
notch = TRUE)

##### Example 6
boxplot(values ~ group, data, # Color of boxplots
col = "red")

##### Example 7
boxplot(values ~ group, data, # Different color for each boxplot
col = c("red", "green", "purple"))

##### Example 8
data2 <- data # Replicate data
data2$group <- c(rep("x1", 500), rep("x2", 500), # Modify group variable
rep("y1", 500), rep("y2", 500),
rep("z1", 500), rep("z2", 500))
boxplot(values ~ group, data2, # Boxplot with manual positions
col = c("blue", "pink"),
at = c(1, 2, 5, 6, 9, 10))

##### Example 9
library("ggplot2")
ggplot(data2, aes(x = group, y = values, fill = group)) + # Create boxplot chart in ggplot2
geom_boxplot()
Рекомендации по теме
Комментарии
Автор

excellent. Many useful examples. Thanks Herr Statistics Globe!

aeroeng
Автор

Thank you for this excellent tutorial, which would help many students and beginners as I. However, I am probably still unable to create a box plot, and I look forward to your help which must highly be appreciated. I want to build three box plots of these numerical below data each month, but I could not make it
Month Observed SDSM GCMs
Jan 0 4 36
Feb 2.3 1 28
Mar 18 13.8 6
Apr 25 28 89
May 55 67 98
Jun 13 27 2
Jul 15 17 84
Aug. 70 82 130
Sep. 25 31 17
Oct. 14 19 9.3
Nov. 0 5 41
Dec. 2 8 26

bernardrobenson
Автор

Great video. Thank you so much. I have a question. I just created a boxplot (i.e. diel cycle of ozone) and I am wondering, is there a way in order to show the time in x axis only for every 3 hours (i.e. the boxplots will appear normally, but in the x axis the sequence will be 3 6 9 etc.)?

Thank you in advance.

stefos
Автор

Your vids are really helpful!! Thank you!

Автор

Hi, how do I add all samples as dots, instead of only the outliers? thanks! great explanation

julespeeters
Автор

Thanks for your a helpful video. Could you please show me how to draw a boxplot with 4 different variables and timeline?

nguyenthithuycntynguyenthi
Автор

hello, can i know how do linear regression in R-Studio?.Can i Contact you privately??

Madush_