I have two problems,
- I want my legends in the order of highest to lowest value or lowest to the highest value. But it shows up in the alphabetic order (EBIT, EBITDA, Gross Profit, Net Profit before Tax, Sales). However, I would like to have them in the order of Sales, Gross Profit, EBITDA, EBIT, Net Profit before Tax)
- In my x-axis I have columns for five years from 2017 to 2021. I would like to have all five years as labels instead of three years automatically showing up (2018, 2020, 2022)
I have done following in R Studio,
install.packages("tidyverse")
library(tidyverse)
install.packages("lubridate")
library(lubridate)
library(dplyr)
install.packages("scales")
library(scales)
library(ggplot2)
five_years_growth <- read.csv("five_years_growth.csv")
five_years_growth$year <- dmy(five_years_growth$year)
five_years_growth$amount <- as.numeric(five_years_growth$amount)
five_years_growth$category <- factor(five_years_growth$category)
ggplot(data = five_years_growth) +
geom_col(mapping = aes(x = year, y = amount, group = reorder(category, -amount), fill = category), position = position_dodge()) +
scale_y_continuous(name = "Amount $", label = comma) +
labs(title = "Key Performance : 2017 to 2021", x = "Financial Year")
I would highly appreciate your help on the above
structure(list(year = structure(c(17347, 17712, 18077, 18443,
18808, 17347, 17712, 18077, 18443, 18808, 17347, 17712, 18077,
18443, 18808, 17347, 17712, 18077, 18443, 18808, 17347, 17712,
18077, 18443, 18808), class = "Date"), category = structure(c(1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L), .Label = c("Sales", "Gross Profit",
"EBITDA", "EBIT", "Net Profit before Tax"), class = "factor"),
amount = c(1e+05, 2e+05, 3e+05, 4e+05, 5e+05, 50000, 1e+05,
150000, 2e+05, 250000, 40000, 80000, 130000, 150000, 175000,
30000, 65000, 1e+05, 120000, 150000, 25000, 50000, 72000,
1e+05, 125000)), row.names = c(NA, -25L), class = "data.frame")