X <- "This is my first assignment"
X[1] "This is my first assignment"
Cal Poly Pomona | IBM 6540
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.
Exercise 1: Create a variable called X and assign the text “This is my first assignment” to it.
Use <- to assign text to a variable.
X <- "This is my first assignment"
X[1] "This is my first assignment"
Exercise 2: Adding texts in Base R.
paste()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"
XX <- paste(X, "and I'm loving it!")
X[1] "This is my first assignment and I'm loving it!"
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
Exercise 4: Print both the variable
Xand the vectorY.
X[1] "This is my first assignment and I'm loving it!"
Y[1] 4 6 8 10
Exercise 5: Show the maximum and minimum value of the vector
Y.
max(Y)[1] 10
min(Y)[1] 4
ggplot2Exercise 6: Load the
ggplot2package and look at the first six rows of theeconomicsdata.
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
Exercise 7: Use the
economicsdata set, define the variables, and create a chart usingggplot2.
The economics data set contains six variables:
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")
)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")
)Exercise 9: Use a callout block to describe your findings and cross-reference the figure.
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.
Exercise 10: Explain what Quarto tools were used to make the report organized and reproducible.
I used the following Quarto tools:
# headings for main report sections.## subheadings for smaller sections.callout-tip blocks for hints.callout-note blocks for findings.callout-important blocks for important reminders.> to show each task.paste(), ggplot(), and labs().@fig-pop-unemploy.#| to control figure label, caption, width, and aspect ratio.styles.css.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.