M01-2 Introduction to Literate Programming

Cal Poly Pomona | IBM 6540

Author

Mickyas Shawel

Published

June 9, 2026

Intro

Introduction to Literate Programming

Student: Mickyas Shawel

Course: IBM 6540

Institution: Cal Poly Pomona

This report demonstrates the application of R programming, data visualization, and reproducible reporting using Quarto.

Creating Variables

Exercise 1: Create a variable called X and assign the text “This is my first assignment” to it.

Tip

Use <- to assign text to a variable.

X <- "This is my first assignment"
X
[1] "This is my first assignment"

Adding Text in Base R

Exercise 2: Adding texts in Base R.

Learning paste()

Tip

Use ?paste to open the help document for the paste() function.

?paste

paste("The life of", pi)
[1] "The life of 3.14159265358979"
paste("The life of", pi, sep = " is ")
[1] "The life of is 3.14159265358979"
paste0("The life of ", pi)
[1] "The life of 3.14159265358979"

Adding Text to X

X <- paste(X, "and I'm loving it!")
X
[1] "This is my first assignment and I'm loving it!"

Working with Vectors

Exercise 3: Create a vector called Y with the numbers 2, 3, 4, and 5. Next, multiply the vector by 2 and save it as Y again.

Y <- c(2, 3, 4, 5)
Y
[1] 2 3 4 5
Y <- Y * 2
Y
[1]  4  6  8 10

Displaying Results

Exercise 4: Print both the variable X and the vector Y.

X
[1] "This is my first assignment and I'm loving it!"
Y
[1]  4  6  8 10

Vector Analysis

Exercise 5: Show the maximum and minimum value of the vector Y.

max(Y)
[1] 10
min(Y)
[1] 4

Loading ggplot2

Exercise 6: Load the ggplot2 package and look at the first six rows of the economics data.

Important

Only run install.packages("ggplot2") if the package is not already installed.

# install.packages("ggplot2")

library(ggplot2)
head(economics)
# A tibble: 6 × 6
  date         pce    pop psavert uempmed unemploy
  <date>     <dbl>  <dbl>   <dbl>   <dbl>    <dbl>
1 1967-07-01  507. 198712    12.6     4.5     2944
2 1967-08-01  510. 198911    12.6     4.7     2945
3 1967-09-01  516. 199113    11.9     4.6     2958
4 1967-10-01  512. 199311    12.9     4.9     3143
5 1967-11-01  517. 199498    12.8     4.7     3066
6 1967-12-01  525. 199657    11.8     4.8     3018

Exploring the Economics Dataset

Exercise 7: Use the economics data set, define the variables, and create a chart using ggplot2.

The economics data set contains six variables:

  • date: Month of data collection.
  • pce: Personal consumption expenditures, in billions of dollars.
  • pop: Total population, in thousands.
  • psavert: Personal savings rate.
  • uempmed: Median duration of unemployment, in weeks.
  • unemploy: Number of unemployed people, in thousands.

I chose population and unemployment because they may be related over time.

plot <- ggplot(
  data = economics,
  mapping = aes(x = pop, y = unemploy)
) +
  geom_point(color = "#005030", alpha = 0.7)

plot +
  labs(
    title = "Population and Unemployment Over Time",
    subtitle = "Economics Dataset from ggplot2",
    x = "Total Population, in Thousands",
    y = "Number of Unemployed People, in Thousands"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.subtitle = element_text(color = "gray40")
  )

Recreating Visualizations with Pipes

Exercise 8: Replicate the chart using a pipe operator without saving the initial plot as an object.

economics |>
  ggplot(aes(x = pop, y = unemploy)) +
  geom_point(color = "#005030", alpha = 0.7) +
  labs(
    title = "Relationship Between Population and Unemployment",
    subtitle = "Economics Dataset from ggplot2",
    x = "Total Population, in Thousands",
    y = "Number of Unemployed People, in Thousands"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold"),
    plot.subtitle = element_text(color = "gray40")
  )
Figure 1: Relationship between total population and unemployment in the economics data set.

Findings

Exercise 9: Use a callout block to describe your findings and cross-reference the figure.

Note

The chart in Figure 1 shows that population and unemployment both change over time in the economics data set. The relationship is not perfectly straight, but the scatterplot suggests that higher population levels are often associated with higher unemployment counts.

Quarto Tools Used

Exercise 10: Explain what Quarto tools were used to make the report organized and reproducible.

I used the following Quarto tools:

  1. I used # headings for main report sections.
  2. I used ## subheadings for smaller sections.
  3. I used bold font to emphasize important words.
  4. I used italicized font for emphasis.
  5. I used callout-tip blocks for hints.
  6. I used callout-note blocks for findings.
  7. I used callout-important blocks for important reminders.
  8. I used blockquotes with > to show each task.
  9. I used backticks around functions like paste(), ggplot(), and labs().
  10. I used figure cross-referencing with @fig-pop-unemploy.
  11. I used code chunk options with #| to control figure label, caption, width, and aspect ratio.
  12. I used a table of contents through the YAML header.
  13. I used a custom CSS file with styles.css.
  14. I used branded color styling inspired by Cal Poly Pomona.

Key Takeaways

Note

Through this assignment, I learned how to create and manipulate variables in R, work with vectors, use packages and built-in datasets, create visualizations using ggplot2, and build reproducible reports with Quarto.