forked from math430-lu/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
mpg <- read.csv(file = "https://github.com/math430-lu/data/raw/master/mpg.csv", as.is = TRUE) | ||
library(ggplot2) | ||
mpg <- read.csv(file = "https://github.com/math430-lu/data/raw/master/mpg.csv") | ||
library(ggplot2) | ||
dim(mpg) | ||
head(mpg) | ||
ggplot(data = mpg, mapping = aes(x = weight, y = mpg)) + | ||
geom_point() | ||
ggplot(data = mpg, mapping = aes(x = weight, y = mpg)) + | ||
geom_point() + | ||
labs(x = "weight (lbs.)", y = "fuel economy (mpg)") | ||
cor(mpg$weight, mpg$mpg) | ||
x <- -5:5 | ||
y <- x^2 | ||
cor(x, y) | ||
ggplot(data = data.frame(x, y), mapping = aes(x, y)) + | ||
geom_point() + | ||
geom_smooth(method = "lm", se = FALSE) | ||
qplot(x3, y3, data = anscombe) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.816", x = 6, y = 12, size = 6) | ||
qplot(x3, y3, data = filter(anscombe, y3 < 9)) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.999", x = 6, y = 12, size = 6) | ||
qplot(x3, y3, data = anscombe) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.816", x = 6, y = 12, size = 6) | ||
qplot(x3, y3, data = subset(anscombe, y3 < 9)) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.999", x = 6, y = 12, size = 6) | ||
grid.arrange(p1, p2, nrow = 1) | ||
qplot(x3, y3, data = anscombe) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.816", x = 6, y = 12, size = 6) | ||
qplot(x3, y3, data = subset(anscombe, y3 < 9)) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.999", x = 6, y = 12, size = 6) | ||
library(gridExtra) | ||
p1 <- qplot(x3, y3, data = anscombe) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.816", x = 6, y = 12, size = 6) | ||
p2 <- qplot(x3, y3, data = subset(anscombe, y3 < 9)) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.999", x = 6, y = 12, size = 6) | ||
grid.arrange(p1, p2, nrow = 1) | ||
1:10 | ||
# You will need to load the package in each R markdown notebook | ||
library(tidyverse) | ||
# Load the data and assign it a name | ||
mpg <- read.csv("https://github.com/math430-lu/data/raw/master/mpg.csv") | ||
# Printing the first 6 rows | ||
# Note that missing values are denoted by NA | ||
head(mpg) | ||
# Printing the last 6 rows | ||
tail(mpg) | ||
# Looking at the number of rows and columns | ||
dim(mpg) | ||
# Looking at the structure | ||
str(mpg) | ||
# Getting a glimpse of the structure | ||
glimpse(mpg) | ||
# looking at the summary | ||
summary(mpg) | ||
ggplot(data = mpg, mapping = aes(x = weight, y = mpg)) + | ||
geom_point() + | ||
labs(x = "weight (lbs.)", y = "fuel economy (mpg)") | ||
cor(mpg$weight, mpg$mpg) | ||
x <- -5:5 | ||
y <- x^2 | ||
cor(x, y) | ||
ggplot(data = data.frame(x, y), mapping = aes(x, y)) + | ||
geom_point() + | ||
geom_smooth(method = "lm", se = FALSE) | ||
library(gridExtra) | ||
p1 <- qplot(x3, y3, data = anscombe) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.816", x = 6, y = 12, size = 6) | ||
p2 <- qplot(x3, y3, data = subset(anscombe, y3 < 9)) + | ||
xlab("x") + ylab("y") + scale_y_continuous(limits=c(5,13)) + | ||
annotate("text", label = "r = 0.999", x = 6, y = 12, size = 6) | ||
grid.arrange(p1, p2, nrow = 1) |