How to create a nice scatter plot in R using ggplot2? | StatswithR | Arnab Hazra

preview_player
Показать описание
Here we explain how to generate a presentation/publication-quality scatter plot plot in R/R-studio using ggplot2. The codes for the steps explained in the video are as follows. Copy and paste them into R, run them one-by-one and try to understand what each argument is doing.

#datascience #datavisualization #visualization #ggplot2 #tidyverse #scatterplot #rstudio #rcoding #normal

rm(list = ls())

library(readr)
library(ggplot2)

mydir = "/home/hazraa/Desktop/youtube/scatterplot"

setwd(mydir)

gretoefldata = read_csv(gretoeflfile)

gre = gretoefldata$`GRE Score`
toefl = gretoefldata$`TOEFL Score`

p = ggplot() + geom_point(aes(x = toefl, y = gre), size = 2)

p = ggplot() + geom_point(aes(x = toefl, y = gre), size = 2) +
xlab("TOEFL Score") + ylab("GRE Score")

p = ggplot() + geom_point(aes(x = toefl, y = gre), size = 2) +
xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE")

p = ggplot() + geom_point(aes(x = toefl, y = gre), size = 2) +
xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +

p = ggplot() + geom_point(aes(x = toefl, y = gre), size = 2) +
xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +

xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +
geom_smooth()

xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +
geom_smooth(method=lm)

xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +
geom_smooth(method=lm, se=FALSE)

xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +
geom_smooth(method = "lm", formula = y ~ poly(x, 3))

library(mgcv)

xlab("TOEFL Score") + ylab("GRE Score") +
ggtitle("TOEFL versus GRE") +
geom_smooth(method = gam, formula = y ~ s(x))

Music used
Quiet Place by Jonny Easton
Check out his channel
Рекомендации по теме
Комментарии
Автор

Sir, I really like your step by step teaching methods. Much appreciated. Could you please provide the CSV file for this exercise? Cannot find it on your webpage. Thanks a lot.

hevea
welcome to shbcf.ru