Video summary
Lecture 03 : Data Visualization- Part 1
Main summary
Key takeaways
Summary
The lecture demonstrates how to create and customize common visualizations in R, progressing from basic plots to time-series plots, bar charts, pie charts, histograms, and grouped or stacked bar charts. A recurring lesson is that many plotting options—such as colors, labels, titles, borders, legends, and layout settings—can be reused across different chart types.
1. Set up the R workspace and import data
- Set a working directory so R can find input files and save plots.
- Import Excel data using RStudio’s Import Dataset option.
- Copy the generated import commands from the console into a script for reuse.
- Use
head()to inspect the beginning of a dataset andsummary()to review its contents.
2. Plot gasoline prices as a time series
Using weekly gasoline-price data:
- Create a line plot with
plot(), specifying the series, line type, title, color, and line width. - Export or copy plots from the plotting window, for example, as an image or PDF.
- Use the zoo package for time-series data:
- Install it if necessary, then load it with
library(zoo). - Convert the price series to a zoo object using the price values and their dates.
- Convert weekly observations to quarterly observations with a quarterly aggregation function.
- Install it if necessary, then load it with
- Compare the weekly and quarterly plots. The weekly series is more variable, while the quarterly series is smoother and makes broader trends easier to see.
- Use
par(mfrow = ...)to display multiple plots in one plotting window.
3. Make a basic bar plot
- Use
barplot()with a series of values and customize the axis labels, color, and border. - Many of the same options used with
plot()also apply to other chart functions. - Set the plotting layout appropriately—for example, to one plot per window—before drawing a single chart.
4. Visualize country outlook ratings
Using the Nations dataset:
- Convert the outlook variable to a factor so it is treated as categorical data.
- Check its categories with
levels()and their counts withtable(). - Plot the category frequencies with
barplot(). - Customize the chart’s:
- Bar colors and borders
- Axis labels and title
- Horizontal or vertical orientation
- Legend location, labels, colors, and size
The example uses three outlook categories—negative, positive, and stable—to show how factor data can be summarized and visualized.
5. Show soft-drink frequency and relative frequency
Using soft-drink brand data:
- Create a frequency table with
table(), then place it in a data frame for convenient plotting. - Calculate each brand’s relative frequency by dividing its count by the total count.
- Use
barplot()to plot relative frequencies, with brand names as category labels. - Try different color schemes, including a rainbow palette, and change the orientation if useful.
- Add a legend with abbreviated brand labels and matching fill colors.
- Create a pie chart with
pie()using relative frequencies:- Label slices with brand names or calculate rounded percentage labels.
- If using percentages as slice labels, add a separate legend to identify the brands.
- Use the plotrix package to create a 3D pie chart; install and load the package if needed.
6. Create and customize histograms
Using a randomly generated sample of 10,000 observations ranging from 50 to 100:
- Inspect the generated values with
summary(). - Plot them with
hist(), customizing the title, axis labels, bar colors, and borders. - Adjust the
breaksargument to change the number of histogram intervals:- Many breaks produce a more detailed distribution.
- Fewer breaks combine observations into broader groups.
- A single break places all observations in one bin.
- Use
par(mfrow = ...)to compare histograms with different numbers of breaks side by side. - Customize the title and axis text size, font, and color.
- Save the histogram result as an object so its bin midpoints and counts can be used to add numeric labels to the bars.
- Overlay a density curve on a histogram by drawing it on the existing plot, adjusting margins as needed, and adding a secondary axis for the density scale. The lecture also demonstrates labeling this secondary axis.
7. Create grouped and stacked bar charts
Using the meal dataset, which records restaurant counts across price ranges and quality ratings:
- Supply the relevant data as a matrix to
barplot(), selecting the rows and columns to include. - Set colors, borders, and axis labels, then add a legend for the quality-rating categories.
- Use the
besideoption to switch between:- Stacked bars, which combine categories within each bar.
- Side-by-side bars, which make category values easier to compare directly.
- Use the horizontal-orientation option to rotate the chart when appropriate.
Speakers and sources featured
- Speaker: An unnamed instructor or narrator presenting an R visualization demonstration.
- Source/channel: IIT Kanpur–NPTEL, as identified in the video metadata.
- Software and data shown: R/RStudio, with gasoline-price, Nations, soft-drink, randomly generated, and meal datasets.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.