la presentation

Quarto

Quarto enables you to weave together content and executable code into a finished presentation. To learn more about Quarto presentations see https://quarto.org/docs/presentations/.

Bullets

When you click the Render button a document will be generated that includes:

  • Content authored with markdown
  • Output from executable code

Code

When you click the Render button a presentation will be generated that includes both content and the output of embedded code. You can embed code like this:

STEP 1. Load required libraries

install.library(ggplot2) → for charts install.library(dplyr) → for data handling install.library(tidyr) → for reshaping data

library(ggplot2)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyr)

STEP 2. Read your CSV data file

This allows us to select the dataset file from the computer.

data <- read.csv(file.choose())  # Click your CSV file when dialog opens

STEP 3. Quick data check (optional - remove if not needed)

head(data) - shows first few rows colnames(data)- shows column names

print("Data preview:")
[1] "Data preview:"
head(data)
  gender race.ethnicity parental.level.of.education        lunch
1 female        group B           bachelor's degree     standard
2 female        group C                some college     standard
3 female        group B             master's degree     standard
4   male        group A          associate's degree free/reduced
5   male        group C                some college     standard
6 female        group B          associate's degree     standard
  test.preparation.course math.score reading.score writing.score
1                    none         72            72            74
2               completed         69            90            88
3                    none         90            95            93
4                    none         47            57            44
5                    none         76            78            75
6                    none         71            83            78
print("Column names:")
[1] "Column names:"
colnames(data)
[1] "gender"                      "race.ethnicity"             
[3] "parental.level.of.education" "lunch"                      
[5] "test.preparation.course"     "math.score"                 
[7] "reading.score"               "writing.score"              

STEP 4. Calculate average scores by test preparation

prep_data <- data %>%
  group_by(test.preparation.course) %>%
  summarise(
    Math = mean(`math.score`, na.rm = TRUE),
    Reading = mean(`reading.score`, na.rm = TRUE),
    Writing = mean(`writing.score`, na.rm = TRUE),
    n_students = n(),  # Count students per group
    .groups = 'drop'
  )

STEP 5. Convert to long format for plotting

prep_long <- prep_data %>%
  pivot_longer(
    cols = c(Math, Reading, Writing),
    names_to = "Subject",
    values_to = "Score"
  )

STEP 6. Create bar chart

p <- ggplot(prep_long,
       aes(x = Subject, 
           y = Score, 
           fill = test.preparation.course)) +
  geom_bar(stat = "identity", 
           position = position_dodge(0.8),
           width = 0.7,
           alpha = 0.85) +
  geom_text(aes(label = round(Score, 1)),
            position = position_dodge(0.8), 
            vjust = -0.25, 
            size = 4,
            fontface = "bold",
            color = "white") +
  scale_fill_brewer(type = "qual", palette = "Set2", name = "Test Prep") +
  labs(title = "Average Scores by Test Preparation Course",
       subtitle = "Math • Reading • Writing | Impact of Preparation",
       x = "Subject",
       y = "Average Score",
       caption = "Data: Student Performance Dataset") +
  theme_minimal(base_size = 14) +
  theme(
    legend.position = "bottom",
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    plot.subtitle = element_text(hjust = 0.5, size = 12, color = "gray50"),
    plot.caption = element_text(hjust = 1, size = 10, color = "gray40"),
    axis.title = element_text(face = "bold"),
    panel.grid.minor = element_blank()
  ) +
  coord_cartesian(ylim = c(0, max(prep_long$Score) * 1.1))

STEP 7. Display plot

This shows the graph on screen.

print(p)

STEP 8. Save high-quality plot (optional)

This saves the chart as an image file.

ggsave("test_prep_scores.png", p, width = 10, height = 7, dpi = 300)
print("Plot saved as 'test_prep_scores.png'")
[1] "Plot saved as 'test_prep_scores.png'"

STEP 9. Show summary table

We print the final average score table. This gives exact values used in the graph.

print("Summary Table:")
[1] "Summary Table:"
print(prep_data)
# A tibble: 2 × 5
  test.preparation.course  Math Reading Writing n_students
  <chr>                   <dbl>   <dbl>   <dbl>      <int>
1 completed                69.7    73.9    74.4        358
2 none                     64.1    66.5    64.5        642