Data Visualization Overview | Dataplexa

Data Visualization Overview in R

In this lesson, you will learn the basics of data visualization in R.

Data visualization is the process of representing data in graphical form so that patterns, trends, and relationships become easy to understand.

Before applying advanced visualization libraries, it is very important to understand the fundamental plotting concepts available in base R.


Why Data Visualization Is Important

Numbers alone can be difficult to interpret, especially when datasets grow large.

Visuals help transform raw data into insights that humans can understand quickly.

  • Helps identify trends and patterns
  • Makes comparisons easier
  • Improves decision-making
  • Communicates results clearly

Basic Plot Types in R

R provides several built-in plotting functions that are simple yet powerful.


Line Plot

A line plot is used to show trends over time or ordered data.

values <- c(10, 15, 18, 22, 30)

plot(values, type = "l",
     main = "Line Plot Example",
     xlab = "Index",
     ylab = "Value")

Bar Plot

A bar plot is used to compare quantities across different categories.

sales <- c(120, 150, 100, 180)
names(sales) <- c("Q1", "Q2", "Q3", "Q4")

barplot(sales,
        main = "Quarterly Sales",
        xlab = "Quarter",
        ylab = "Sales")

Histogram

A histogram shows the distribution of numeric data.

It helps understand how values are spread across ranges.

scores <- c(55, 60, 62, 70, 75, 80, 85, 90, 95)

hist(scores,
     main = "Score Distribution",
     xlab = "Scores")

Scatter Plot

A scatter plot shows the relationship between two numeric variables.

It is commonly used to identify correlations.

x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 5, 7, 8)

plot(x, y,
     main = "Scatter Plot Example",
     xlab = "X Values",
     ylab = "Y Values")

Customizing Plots

R allows customization of plots using parameters such as colors, titles, and labels.

This improves readability and presentation quality.

barplot(sales,
        col = "skyblue",
        border = "black",
        main = "Customized Bar Plot")

🧩 Mini Project: Sales Performance Visualization


📌 Project Question

You are given monthly sales data for a small business.

Your task is to:

  • Store the sales data
  • Create a bar chart to visualize monthly sales
  • Create a line chart to show sales trend
  • Interpret the results

📌 Given Data

months <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun")
sales <- c(200, 240, 300, 280, 350, 400)

📌 Solution Code

# Bar Plot
barplot(sales,
        names.arg = months,
        col = "lightgreen",
        main = "Monthly Sales Performance",
        xlab = "Month",
        ylab = "Sales")

# Line Plot
plot(sales, type = "l",
     xaxt = "n",
     col = "blue",
     main = "Sales Trend Over Time",
     xlab = "Month",
     ylab = "Sales")
axis(1, at = 1:length(months), labels = months)

📌 Explanation

The bar plot allows easy comparison of sales between months.

The line plot clearly shows an upward trend, indicating improving business performance over time.

Together, these visualizations provide both comparison and trend analysis.


📝 Practice Exercises


Exercise 1

Create a bar plot for product-wise sales.

Exercise 2

Create a histogram for exam scores.

Exercise 3

Create a scatter plot showing height vs weight.

Exercise 4

Customize a plot using colors and titles.


✅ Practice Answers


Answer 1

products <- c(120, 180, 150)
names(products) <- c("A", "B", "C")
barplot(products)

Answer 2

marks <- c(65, 70, 75, 80, 85, 90)
hist(marks)

Answer 3

height <- c(150, 160, 170, 180)
weight <- c(50, 60, 70, 80)
plot(height, weight)

Answer 4

plot(values, col = "red", main = "Customized Plot")

What’s Next?

You have now completed the Intermediate Level of the R course.

In the next lesson, you will begin the Advanced Level with ggplot2 Basics.