0
0
R Programmingprogramming~30 mins

Themes and theme customization in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Themes and Theme Customization in R
📖 Scenario: You are creating a simple bar chart to show sales data for different products. You want to make the chart look nicer by changing the theme colors and text styles.
🎯 Goal: Build a bar chart using ggplot2 with a customized theme that changes the background color, text size, and axis titles.
📋 What You'll Learn
Create a data frame called sales_data with products and their sales numbers
Create a variable called base_size to set the base font size for the theme
Use ggplot() to create a bar chart with geom_bar() using sales_data
Customize the plot theme using theme() to change background color, axis title size, and text color
Print the final plot
💡 Why This Matters
🌍 Real World
Customizing themes helps make charts clearer and more attractive for presentations and reports.
💼 Career
Data analysts and scientists often need to adjust chart styles to match company branding or improve readability.
Progress0 / 4 steps
1
Create the sales data
Create a data frame called sales_data with these exact entries: Product as 'A', 'B', 'C' and Sales as 30, 45, 25.
R Programming
Need a hint?

Use data.frame() with Product = c('A', 'B', 'C') and Sales = c(30, 45, 25).

2
Set the base font size
Create a variable called base_size and set it to 14 to control the font size in the theme.
R Programming
Need a hint?

Just assign 14 to base_size.

3
Create the bar chart with customized theme
Use ggplot() with sales_data, map Product to x and Sales to y, add geom_bar(stat = 'identity'), and customize the theme with theme() to set panel.background to light gray, axis title text size to base_size, and axis text color to blue.
R Programming
Need a hint?

Use theme() to customize background and text styles.

4
Display the customized plot
Print the plot stored in the variable plot to display the customized bar chart.
R Programming
Need a hint?

Use print(plot) to show the plot.