Data Visualization in R Complete 20 Pages Notes
Data Visualization in R Complete 20 Pages Notes
Data Visualization is the graphical representation of data using visual elements like charts, graphs,
It helps in understanding trends, patterns, correlations, and outliers.
In Data Science, visualization is a core component of Exploratory Data Analysis (EDA).
Objectives:
- Simplify complex datasets
- Identify relationships between variables
- Detect anomalies
- Support decision-making
2. Importance in Business and Research
Important parameters:
- main: Title
- xlab, ylab: Axis labels
- col: Color
- pch: Point character
- type: Type of plot (p, l, b, etc.)
Example:
x <- 1:10
y <- x^2
plot(x, y, type="b", col="blue", main="Quadratic Plot")
5. Types of Plots in R
Key Terms:
- Frequency
- Density
- Bins
- Range
Boxplot components:
- Minimum
- Q1 (25%)
- Median (50%)
- Q3 (75%)
- Maximum
- Outliers
Syntax:
boxplot(data, col="orange")
8. Introduction to ggplot2
Install:
[Link]("ggplot2")
library(ggplot2)
Basic Structure:
ggplot(data, aes(x, y)) + geom_point()
9. Grammar of Graphics
Components:
- Data
- Aesthetic mappings (aes)
- Geometric objects (geom_)
- Statistical transformations
- Scales
- Coordinates
- Facets
- Themes
Example:
ggplot(mtcars, aes(x=wt, y=mpg)) +
geom_point(color="red") +
ggtitle("Weight vs MPG")
11. Bar Plot using ggplot2
Example:
ggplot(mtcars, aes(x=factor(cyl))) +
geom_bar(fill="purple")
12. Histogram using ggplot2
Example:
ggplot(mtcars, aes(x=mpg)) +
geom_histogram(bins=10, fill="green")
13. Boxplot using ggplot2
Example:
ggplot(mtcars, aes(x=factor(cyl), y=mpg)) +
geom_boxplot(fill="orange")
14. Faceting
Themes:
- theme_minimal()
- theme_classic()
- theme_bw()
Customization:
- scale_color_manual()
- labs()
- theme()
16. Interactive Visualization with Plotly
Install:
[Link]("plotly")
library(plotly)
Example:
plot_ly(data=mtcars, x=~wt, y=~mpg, type='scatter', mode='markers')
17. Data Visualization Best Practices
Example:
ggplot(data, aes(x=date, y=sales)) +
geom_line()
19. Correlation and Regression Visualization
- Business Intelligence
- Healthcare analytics
- Marketing analysis
- Financial modeling
- Machine learning visualization
Visualization is essential before modeling and after prediction for result interpretation.