Skip to content
Learn Netverks

Lesson

Step 20/36 56% through track

ggplot2-aesthetics

ggplot2 aesthetics (local)

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches ggplot2 aesthetics (local): the syntax, patterns, and safety habits you need before advancing in R.

ggplot2 grammar of graphics is the standard viz layer—layer aesthetics before tweaking base plots.

You will apply ggplot2 aesthetics (local) in contexts like: Publication charts, EDA notebooks, and stakeholder dashboards.

Write R in the editor and click Run on server—the dev runner executes with Rscript; use print() or cat() and base R in playground snippets (tidyverse locally; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Aesthetics control color, fill, size, shape, and linetype—often driven by factors. Use consistent palettes and accessible contrast in production reports.

Color by category (local)

ggplot(df, aes(x = week, y = score, color = group)) +
  geom_line()

Factor-driven legends

df <- data.frame(
  week = rep(1:3, 2),
  score = c(80, 85, 90, 78, 82, 88),
  group = factor(rep(c("A", "B"), each = 3))
)
print(df)

Important interview questions and answers

  1. Q: Color vs fill?
    A: Color affects lines/points; fill affects bar/box interior—geom-dependent.
  2. Q: Accessibility?
    A: Do not rely on color alone—add labels, patterns, or direct annotations.

Self-check

  1. Why map group to color in aes?
  2. What R type helps control legend order?

Tip: Map discrete variables to color and continuous to size thoughtfully—check colorblind-safe palettes.

Interview prep

Map color to factor?

Discrete groups get distinct colors with a legend automatically.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • facet_wrap when?
  • theme_minimal?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump