Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Aravind Hebbali aravindhebbali

🏠
Working from home
View GitHub Profile
@aravindhebbali
aravindhebbali / viz_facet.R
Last active Sep 26, 2017
Data Visualization: Combining Plots
View viz_facet.R
# 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 Sep 26, 2017
Data Visualization: Text Annotations
View viz_annotations.R
# 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 Sep 26, 2017
Data Visualization: Legends
View viz_legend.R
# 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 Sep 26, 2017
Data Visualization: Histogram
View vis_hist.R
# 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 Sep 26, 2017
Data Visualization: Box Plots
View viz_box.R
# 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 Sep 26, 2017
Data Visualization: Bar Plots
View viz_bar.R
# 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
@aravindhebbali
aravindhebbali / viz_line.R
Last active Sep 26, 2017
Data Visualization: Line Graphs
View viz_line.R
# data
head(AirPassengers)
# plot
data <- head(AirPassengers)
plot(data, type = 'l')
plot(data, type = 'b')
plot(data, type = 'o')
plot(data, type = 'c')
@aravindhebbali
aravindhebbali / viz_scatter.R
Last active Sep 26, 2017
Data Visualization: Scatter Plots
View viz_scatter.R
# scatter plot
plot(mtcars$disp, mtcars$mpg)
# add title and axis labels
plot(mtcars$disp, mtcars$mpg,
main = 'Displacement vs Miles Per Gallon',
xlab = 'Displacement', ylab = 'Miles Per Gallon')
# point shape
plot(mtcars$disp, mtcars$mpg, pch = 6)
@aravindhebbali
aravindhebbali / viz_title_axis_labels.R
Last active Sep 26, 2017
Data Visualization: Title & Axis Labels
View viz_title_axis_labels.R
# title
plot(mtcars$disp, mtcars$mpg,
main = 'Displacement vs Miles Per Gallon')
# subtitle
plot(mtcars$disp, mtcars$mpg,
main = 'Displacement vs Miles Per Gallon',
sub = 'Mileage is inversely related to Displacement')
# axis labels
@aravindhebbali
aravindhebbali / viz_intro.R
Last active Sep 26, 2017
Data Visualization: Introduction
View viz_intro.R
# help
help(plot)
help(mtcars)
# mtcars
head(mtcars)
# variable info
str(mtcars)
You can’t perform that action at this time.