Reputation: 29
Can someone help me with the following?
my data frame looks like below:
tibble::tribble(
~date, ~ratio_type, ~percentage,
"30/06/2016", "gp", 0.25,
"30/06/2016", "EBIT", 0.20,
"30/06/2017", "gp", 0.30,
"30/06/2017", "EBIT", 0.18,
)
It reads date as date, ratio_type as character, and percentage as numeric.
I have two problems:
Upvotes: 0
Views: 419
Reputation: 15143
1.scale::label_percent()
convert numeric value to percentage in R
2.position = position_dodge()
will separate columns and scale_y_continuous(labels = scales::percent)
will make y axis percentage.
df %>% mutate(date = as.Date(date, "%d/%m/%Y")) %>%
ggplot(aes(x = date, y= percentage, group = ratio_type, fill = ratio_type)) +
geom_col(position = position_dodge()) + scale_y_continuous(labels = scales::percent)
Upvotes: 1