# load packages
library(olsrr)
#>
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#>
#> rivers
# regression
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
# install the package | |
install.packages("RMySQL") | |
# load the package | |
library(RMySQL) | |
# create a MySQL connection object | |
con <- dbConnect(MySQL(), |
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
import numpy as np | |
# create two dimensional arrays | |
np1 = np.arange(0, 9).reshape(3, 3) | |
np1 | |
np2 = np1 * 5 | |
np2 | |
# horizontal stacking |
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
# install | |
install.packages('ggplot2') | |
install.packages('readr') | |
# load | |
library(ggplot2) | |
library(readr) | |
# Scatter Plot | |
p <- ggplot(mtcars) + |
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
# Case Study 1: combine 4 plots in 2 rows and 2 columns | |
# store the current parameter settings in init | |
init <- par(no.readonly=TRUE) | |
# specify that 4 graphs to be combined and filled by rows | |
par(mfrow = c(2, 2)) | |
# specify the graphs to be combined | |
plot(mtcars$mpg) | |
plot(mtcars$disp, mtcars$mpg) |
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
# text inside plot | |
plot(mtcars$disp, mtcars$mpg) | |
text(x = 340, y = 30, labels = 'Sample Text') | |
# color | |
plot(mtcars$disp, mtcars$mpg) | |
text(x = 340, y = 30, labels = 'Sample Text', col = 'red') | |
# font | |
plot(mtcars$disp, mtcars$mpg) |
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
# data | |
year <- seq(2010, 2014, 1) | |
india <- c(10.3, 6.6, 5.6, 6.6, 7.2) | |
china <- c(10.6, 9.5, 7.8, 7.7, 7.3) | |
russia <- c(4.5, 4.3, 3.5, 1.3, 0.7) | |
brazil <- c(7.5, 3.9, 1.9, 3.0, 0.1) | |
s_africa <- c(3.2, 3.2, 2.2, 2.2, 1.5) | |
gdp <- data.frame(year, india, china, russia, brazil, s_africa, stringsAsFactors = FALSE) | |
gdp |
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
# distributions | |
# normal distribution | |
hist(rbeta(10000, 5, 5), ann = FALSE, col = 'blue') | |
# skewed distributions | |
hist(rbeta(10000, 2, 5), ann = FALSE, col = 'blue') | |
hist(rbeta(10000, 5, 2), ann = FALSE, col = 'blue') | |
# histogram | |
# store the results of hist function |
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
# basic plot | |
boxplot(mtcars$mpg) | |
# horizontal box plot | |
boxplot(mtcars$mpg, horizontal = TRUE) | |
# color | |
boxplot(mtcars$mpg, col = 'blue') | |
# border color |
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
# using plot function | |
plot(as.factor(mtcars$cyl)) | |
# using bar plot function | |
barplot(table(mtcars$cyl)) | |
# tabulated data | |
cyl_freq <- table(mtcars$cyl) | |
cyl_freq |
NewerOlder