Click the Original, Code and Reconstruction tabs to read about the issues and how they were fixed.
Objective
This is a visualisation about number of sales from several credible automobile brands which can interest car lovers and car professionals
The visualisation chosen had the following three main issues:
Reference
The following code was used to fix the issues identified in the original.
#Preprocessing
car_sales = read.csv("Car_sales.csv")
print(car_sales)
## ï..Automaker U.S..Sales.in.2021
## 1 General Motors 2300000
## 2 Toyota 2200000
## 3 Ford 1900000
## 4 Volkswagen Group 630000
## 5 Tesla 361000
## 6 Mercedes-Benz 330000
## 7 Xpeng 98000
## 8 NIO 91000
## 9 Rivian 920
## 10 Lucid 520
#Adding country of the manufacturer to provide a better colour division
Country <- c("USA", "Japan", "USA", "Germany", "USA", "Germany", "China", "China", "USA", "USA")
car_sales <- cbind(car_sales, Country)
colnames(car_sales) <- c('Automaker', 'Sales_in_USA', 'Country' )
#Issue 1
library(ggplot2)
library(tidyverse)
p <- ggplot(data = car_sales) +
geom_bar(mapping = aes(y=Automaker, x=Sales_in_USA), stat = 'identity')
#Issue 2
p + ggtitle("Sales from each car brand in 2021") +
labs(x = "Number of sales", y = "manufacturer")+ theme(axis.text.x = element_text(size = 10), axis.text.y = element_text(size = 10), plot.title = element_text(size=20, face = "bold", color = "#5698D6", hjust = 0.5, vjust = 2))
#Issue 3 plus final reconstruction
library(scales)
#Used for putting comm on xlabel values
p <- ggplot(data = car_sales, aes(y = reorder(Automaker, Sales_in_USA ), x = Sales_in_USA, fill = Country)) +
geom_bar( stat = 'identity')+ ggtitle("Sales from each car brand in 2021") +
labs(x = "Number of sales", y = "manufacturer")+ theme(axis.text.x = element_text(size = 10), axis.text.y = element_text(size = 10), plot.title = element_text(size=20, face = "bold", color = "#5698D6", hjust = 0.5, vjust = 2)) + geom_text(aes(label = Sales_in_USA), hjust = -0.4, size = 3.5) + scale_x_continuous(label = comma) + expand_limits(x = 3000000)
#ref = https://stackoverflow.com/questions/37713351/formatting-ggplot2-axis-labels-with-commas-and-k-mm-if-i-already-have-a-y-sc
library(ggimage)
library(dplyr)
library(png)
library(grid)
#A couple of packages for image processing
img <- list.files(system.file("logos", package="ggimage"),
pattern="png", full.names=TRUE)
image = sample(img, size=10, replace = TRUE)
g <- p + geom_image(aes(image=img), size=.05)
Data Reference
The following plot fixes the main issues in the original.