Bren85
Bren85

Reputation: 63

R Values as £ Currency

I am trying to convert R values to currency eg 74.02 to £74.02. From other similar queries I have unsuccessfully tried to use methods such as setClass("poundFmt").

My code is:

library(tidyverse)
library(ggplot2)

mydf <- data.frame( Category = c("Average"),
                    Example1=c(73.78),
                    Example2=c(74.32),
                    Example3=c(74.33),
                    Example4=c(84.02))

mydf %>%
  gather(Month, Total, -Category) %>%
  mutate(Month = reorder(Month, row_number())) %>%
  mutate(Category = reorder(Category, row_number())) %>%
  ggplot(aes(Month, Total, fill = Month, group = Category)) +
  geom_bar(stat = "identity", position = "dodge", width=0.5, fill="orange") +
  geom_text(aes(label=Total),position = position_dodge(width = .3), hjust=1.3, size = 4)+
  coord_flip() +
  labs(x = "", y = "", title = "Example Title", subtitle = "Example Subtitle", legend=FALSE) +
  theme_bw() +
  theme(panel.grid.major.x = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(hjust = 0),
        axis.text.x = element_text(size = 10, face = "bold"),
        axis.text.y = element_text(size = 10, face = "bold"),
        legend.position = "none") +
  scale_y_continuous(labels = abs, limits = c(0, 30))

Upvotes: 1

Views: 110

Answers (1)

PeCaDe
PeCaDe

Reputation: 374

As you are trying to plot an amount with some currency symbol, I suggest you to perform with this code:

ggplot(data = mydf) + 
  geom_point(aes(x = x, y = y)) + 
  scale_x_continuous(labels = scales::dollar_format()) + 
  scale_y_continuous(labels = scales::dollar_format(prefix="£"))

Upvotes: 1

Related Questions