Introduction to ggplot2 Package in R | Data Visualization Tutorial for Beginners & Advanced Examples

preview_player
Показать описание

Table of contents:

00:00 - Introduction
00:42 - Grammar of Graphics & ggplot2 Layers
02:02 - Basic Application of ggplot2 Package
13:24 - Advanced Data Visualization
33:04 - Outro

R code of this video:

y = c(3, 1, 4,
3, 5, 2,
1, 2, 3),
group = rep(LETTERS[1:3], each = 3))
data # Print example data

library("ggplot2") # Load ggplot2

ggplot(data, # Draw basic ggplot2 scatterplot
aes(x = x,
y = y)) +
geom_point()

ggplot(data, # Increase point size
aes(x = x,
y = y)) +
geom_point(size = 3)

ggplot(data, # Set colors by groups
aes(x = x,
y = y,
col = group)) +
geom_point(size = 3)

ggp_simple <- ggplot(data, # Store ggplot2 plot in data object
aes(x = x,
y = y,
col = group)) +
geom_point(size = 3)

ggp_simple + # Change x-axis limits
scale_x_continuous(limits = c(- 3, 15))

ggp_simple + # Change colors by groups
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08"))

ggp_simple + # Add multiple scale layers
scale_x_continuous(limits = c(- 3, 15)) +
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08"))

ggp_simple + # Create subplots using facet_wrap()
scale_x_continuous(limits = c(- 3, 15)) +
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08")) +
facet_wrap(group ~ .)

ggp_simple + # Change ggplot2 theme
scale_x_continuous(limits = c(- 3, 15)) +
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08")) +
facet_wrap(group ~ .) +
theme_bw()

ggp_simple + # Remove legend from plot
scale_x_continuous(limits = c(- 3, 15)) +
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08")) +
facet_wrap(group ~ .) +
theme_bw() +

ggp_simple + # Remove axis information
scale_x_continuous(limits = c(- 3, 15)) +
scale_color_manual(breaks = c("A", "B", "C"),
values = c("#1b98e0", "#353436", "#e32f08")) +
facet_wrap(group ~ .) +
theme_bw() +

Follow me on Social Media:

License code: UPK3JXJBTLOEWP2T
Рекомендации по теме
Комментарии
Автор

Excellent tutorial! I have always found ggplot2 confusing, but in the video all is very clearly explained. Thank you.

rodneyjones
Автор

Thank You Joachim Loving The New Channel Format!Great Tutorial Dude!!

darrylmorgan
Автор

Such a great teacher! honestly the best explanation of ggplot that I have seen on Youtube!

magdawaits
Автор

This was a great intro to ggplot(). Within 30 minutes, you were able share enough of the basics so a beginner could easily create impressive graphics. The only thing I'd be careful about is making column names that match parameter names (example: aes(x = x, y = y)). This can be a bit confusing. 👏

gecarter
Автор

Excellent presentation and perfect explanation of ggplot2 package. I owe you a lot for getting experience in R. Please, keep up the great work.
I just want to ask you if you can make a tutorial on the (lubridate) package, as - I believe - you are the best person that can explain it in an elegant way.
Again, thank you so much.
😊😊😊😊

muhammedhadedy
Автор

Excellent work as usual. It misses only one thing. The video should be divided in sections.

ramgouveia
Автор

Thank You, Excellent tutorial!
Do you have a video about GPCM analysis and scree plots of grain parameter invariance tests?

anteachmad
Автор

coding line 123 to 125 does not work for me, I get error : Error in aggregate.data.frame(diamonds, price ~ clarity, mean) : 'by' must be a list.
anyone can help?

AnseloSilver
Автор

Im trying to plot ggplot but it's not getting. My data set has two variable or samples collected from same place, places Or location grouped in to 5 places. So total data points are 24 that is 24 x nd 24 y. so how to write command. I got basic scatter plot.. But in that place is not coming. X nd y, that are the variable from same places . As I have 5 locations. Help me over this😢😢 I saw full video... Tried faucet also.. Not getting...

kpkavitha