library(tidyverse)Warning: package 'tidyverse' was built under R version 4.5.2
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'dplyr' was built under R version 4.5.1
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 4.0.0 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
qatarcars <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-12-09/qatarcars.csv")Rows: 105 Columns: 15
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): origin, make, model, type, enginetype
dbl (10): length, width, height, seating, trunk, economy, horsepower, price,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(qatarcars)Rows: 105
Columns: 15
$ origin <chr> "Germany", "Germany", "Germany", "Germany", "Germany", "Ge…
$ make <chr> "BMW", "BMW", "Audi", "Audi", "Audi", "Mercedes", "Mercede…
$ model <chr> "3 Series Sedan", "X1", "RS Q8", "RS3", "A3", "Maybach", "…
$ length <dbl> 4.713, 4.505, 5.012, 4.542, 4.456, 5.469, 4.613, 5.216, 4.…
$ width <dbl> 1.827, 1.845, 1.694, 1.851, 1.960, 1.921, 1.984, 1.926, 1.…
$ height <dbl> 1.440, 1.642, 1.998, 1.412, 1.416, 1.510, 1.969, 1.512, 1.…
$ seating <dbl> 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 2, 2, 5…
$ trunk <dbl> 59, 505, 605, 321, 425, 500, 480, 610, 435, 565, 132, 627,…
$ economy <dbl> 7.6, 6.6, 12.1, 8.7, 6.5, 13.3, 13.1, NA, 5.6, 7.5, 11.2, …
$ horsepower <dbl> 386, 313, 600, 400, 180, 612, 585, 333, 163, 221, 473, 453…
$ price <dbl> 164257, 264000, 630000, 310000, 165000, 1281000, 1011500, …
$ mass <dbl> 1653, 1701, 2490, 1565, 1325, 2376, 2588, 2495, 1565, 1656…
$ performance <dbl> 4.3, 5.4, 3.6, 3.8, 6.7, 4.1, 4.3, 5.6, 6.8, 9.0, 3.3, 4.4…
$ type <chr> "Sedan", "SUV", "SUV", "Sedan", "Sedan", "Sedan", "SUV", "…
$ enginetype <chr> "Petrol", "Petrol", "Petrol", "Petrol", "Petrol", "Petrol"…
qatarcars %>%
group_by(enginetype) %>%
summarise(
avg_price = mean(price, na.rm = TRUE),
avg_performance = mean(performance, na.rm = TRUE) )# A tibble: 3 × 3
enginetype avg_price avg_performance
<chr> <dbl> <dbl>
1 Electric 1044377 5.4
2 Hybrid 372257. 6.09
3 Petrol 839319. 7.49
summary_data <- qatarcars %>%
group_by(enginetype) %>%
summarise(
avg_price = mean(price, na.rm = TRUE),
avg_performance = mean(performance, na.rm = TRUE) ) %>%
pivot_longer(
cols = c(avg_price, avg_performance),
names_to = "metric",
values_to = "value" )
summary_data# A tibble: 6 × 3
enginetype metric value
<chr> <chr> <dbl>
1 Electric avg_price 1044377
2 Electric avg_performance 5.4
3 Hybrid avg_price 372257.
4 Hybrid avg_performance 6.09
5 Petrol avg_price 839319.
6 Petrol avg_performance 7.49
ggplot(summary_data, aes(x = enginetype, y = value, fill = metric)) +
geom_col(position = "dodge") +
labs(
title = "Car Prices and Performance by Engine Type in Qatar",
x = "Engine Type",
y = "Value",
fill = "Metric" ) +
theme_minimal()ggplot(
summary_data %>% filter(metric == "avg_price"),
aes(x = enginetype, y = value, fill = enginetype) ) +
geom_col() +
labs(
title = "Average Car Price by Engine Type in Qatar",
x = "Engine Type",
y = "Average Price (QAR)" ) +
theme_minimal()ggplot(
summary_data %>% filter(metric == "avg_performance"),
aes(x = enginetype, y = value, fill = enginetype)
) +
geom_col() +
labs(
title = "Average Car Performance by Engine Type in Qatar",
x = "Engine Type",
y = "Average Performance"
) +
theme_minimal()