Skip to content

Instantly share code, notes, and snippets.

View aravindhebbali's full-sized avatar
🏠
Working from home

Aravind Hebbali aravindhebbali

🏠
Working from home
View GitHub Profile
@aravindhebbali
aravindhebbali / rmysql_gist.R
Last active June 6, 2023 06:34
RMySQL Tutorial Gist
# install the package
install.packages("RMySQL")
# load the package
library(RMySQL)
# create a MySQL connection object
con <- dbConnect(MySQL(),
@aravindhebbali
aravindhebbali / sort-best-subset.md
Last active March 8, 2022 06:50
Sort best subset selection by AIC
# load packages
library(olsrr)
#> 
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

# regression
@aravindhebbali
aravindhebbali / gist_numpy_combine_split.py
Created February 15, 2016 11:39
NumPy for Beginners: Combine/Split NumPy Arrays
import numpy as np
# create two dimensional arrays
np1 = np.arange(0, 9).reshape(3, 3)
np1
np2 = np1 * 5
np2
# horizontal stacking
@aravindhebbali
aravindhebbali / gg_themes.R
Last active November 15, 2017 18:22
ggplot2: Themes
# install
install.packages('ggplot2')
install.packages('readr')
# load
library(ggplot2)
library(readr)
# Scatter Plot
p <- ggplot(mtcars) +
@aravindhebbali
aravindhebbali / viz_facet.R
Last active September 26, 2017 09:18
Data Visualization: Combining Plots
# 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)
@aravindhebbali
aravindhebbali / viz_annotations.R
Last active September 26, 2017 09:05
Data Visualization: Text Annotations
# 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)
@aravindhebbali
aravindhebbali / viz_legend.R
Last active September 26, 2017 08:47
Data Visualization: Legends
# 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
@aravindhebbali
aravindhebbali / vis_hist.R
Last active September 26, 2017 08:33
Data Visualization: Histogram
# 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
@aravindhebbali
aravindhebbali / viz_box.R
Last active September 26, 2017 08:18
Data Visualization: Box Plots
# basic plot
boxplot(mtcars$mpg)
# horizontal box plot
boxplot(mtcars$mpg, horizontal = TRUE)
# color
boxplot(mtcars$mpg, col = 'blue')
# border color
@aravindhebbali
aravindhebbali / viz_bar.R
Last active September 26, 2017 08:14
Data Visualization: Bar Plots
# 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