STEP 1: Setup Packages

Install required packages (run once)

install.packages(c(“ggplot2”, “plotly”, “leaflet”, “rmarkdown”, “tidyverse”, “gapminder”, “knitr”))

library(ggplot2) library(plotly) library(leaflet) library(tidyverse) library(gapminder) library(knitr)

data(“mtcars”) data(“gapminder”) data(“quakes”)

bar_plot <- mtcars %>% group_by(cyl) %>% summarise(avg_mpg = mean(mpg)) %>% ggplot(aes(x = factor(cyl), y = avg_mpg, fill = factor(cyl))) + geom_col() + labs(title = “Average MPG by Cylinder”, x = “Cylinders”, y = “Average MPG”)

2. Line Plot: GDP per Capita over Time for India

line_plot <- gapminder %>% filter(country == “India”) %>% ggplot(aes(x = year, y = gdpPercap)) + geom_line(color = “steelblue”, size = 1.2) + labs(title = “GDP Per Capita Over Time - India”, x = “Year”, y = “GDP Per Capita”)

3. Scatter Plot: Life Expectancy vs GDP

scatter_plot <- gapminder %>% ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) + geom_point(alpha = 0.6) + scale_x_log10() + labs(title = “Life Expectancy vs GDP”, x = “GDP Per Capita (log scale)”, y = “Life Expectancy”)

4. Interactive Map: Earthquake Locations

quake_map <- leaflet(data = quakes[1:100, ]) %>% addTiles() %>% addCircleMarkers(~long, ~lat, radius = ~mag, popup = ~paste(“Magnitude:”, mag))

title: “My Data Visualization Portfolio” author: “Sukumar Elley” output: R_document: theme: cerulean toc: true editor_options: markdown: wrap: 72 —

📊 Introduction

Welcome to my data visualization portfolio! This site showcases a few projects created in R using ggplot2, plotly, and leaflet.

🔹 Visualization 1: Average MPG by Cylinder

mtcars %>%
  group_by(cyl) %>%
  summarise(avg_mpg = mean(mpg)) %>%
  ggplot(aes(x = factor(cyl), y = avg_mpg, fill = factor(cyl))) +
  geom_col() +
  labs(title = "Average MPG by Cylinder", x = "Cylinders", y = "Average MPG")

🔹 Visualization 2: GDP Over Time (India)

gapminder %>%
  filter(country == "India") %>%
  ggplot(aes(x = year, y = gdpPercap)) +
  geom_line(color = "steelblue", size = 1.2) +
  labs(title = "GDP Per Capita Over Time - India", x = "Year", y = "GDP Per Capita")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

🔹 Visualization 3: Life Expectancy vs GDP

gapminder %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) +
  geom_point(alpha = 0.6) +
  scale_x_log10() +
  labs(title = "Life Expectancy vs GDP", x = "GDP Per Capita (log scale)", y = "Life Expectancy")

🔹 Visualization 4: Earthquake Map (Interactive)

leaflet(data = quakes[1:100, ]) %>%
  addTiles() %>%
  addCircleMarkers(~long, ~lat, radius = ~mag, popup = ~paste("Magnitude:", mag))

📝 Conclusion

This is a basic portfolio website showing visualizations using open datasets. All charts were built using R’s ggplot2, leaflet, and plotly.