📎 This article includes 2 downloadable practice files ↓
📘 R Beginner Course · Lesson 5 of 6
“`r
by_region <- sales |> group_by(region) |> summarise(sales = sum(amount))
ggplot(by_region, aes(x = reorder(region, sales), y = sales / 1e5)) +
geom_col(fill = “#c2410c”) + coord_flip() +
labs(title = “Sales by region”, x = NULL, y = “Rs lakh”) + theme_minimal()
ggsave(“sales_by_region.png”, width = 6, height = 4)
“`
Every ggplot has data, aesthetics (which column goes on x, y, colour) and a geometry (geom_col bars, geom_line lines, geom_point dots). Layers are added with +.
💡 reorder(region, sales) sorts bars by value, the single biggest readability improvement for bar charts.
More: ggplot2 for Excel users .
Code for this course follows standard, current syntax; we test JavaScript and PowerShell scripts before publishing, and R/Java/Rust examples are kept to core language features. Tell us if anything fails on your setup.
Practice
Run the script and open the saved PNG.
← R Lesson 4: dplyr — filter, mutate, summarise R Lesson 6: Project — A Sales Analysis Report →
📎 Practice files for this article Free to use for learning. Files with macros (.bas) are plain text — import them with Alt +F11 → File → Import File, and always test on a copy.
Written by Atul Vij Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul → ← Previous R Lesson 4: dplyr — filter, mutate, summariseNext → R Lesson 6: Project — A Sales Analysis Report
✨ Ask AI about this article Stuck on a step? Ask a question and the AI answers using this article.
Your question about this article Model Auto — best model for the task GPT-OSS 120B — OpenAI · strongest reasoning · counts as 2 DeepSeek R1 — DeepSeek · thinks step by step (slow) · counts as 2 Llama 3.3 70B — Meta · fast, all-round Qwen 2.5 Coder 32B — Alibaba · best for code Gemma 4 26B — Google · clear explanations Mistral Small 3.1 — Mistral · quick GPT-OSS 20B — OpenAI · balanced Llama 4 Scout — Meta · newest Llama Gemma Sea Lion V4 27b — Aisingapore Glm 4.7 Flash — Zai-org Llama 3.1 8b — Meta Llama 3.2 3b — Meta Nemotron 3 120b A12b — Nvidia · counts as 2 Qwen3 30b A3b — Qwen Qwen3.8 27b — Qwen Qwq 32b — Qwen · counts as 2 Free · AI can be wrong Ask ✨