0

I have a dataframe that looks like this:

year <- c("2015", "2016", "2017", "2018")
malaria_mortality <- c(25, 30, 35, 40)
malaria_discharge <- c(155, 340, 550, 160)

fatality <- data.frame(year, malaria_mortality,malaria_discharge )

I want to generate percentage proportion by calculating value from malaria mortality column to value from malaria discharge column, Which i achieve by doing this:

fatality$case_fatal <- round((fatality$malaria_mortality/fatality$malaria_discharge) * 100, 2)

I then went ahead and generated a plot that looks like this

p <-ggplot(fatality, aes(x=year, y=case_fatal)) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_minimal() +
  labs(title="Case Fatality ") +
  geom_text(aes(label=case_fatal), vjust=1.6, color="white",
            position = position_dodge(0.9), size=3.5)

p

Everything is okey, however, how can I add percentage sign (%) to the bargraph labels. Any assistance to add percentage sign on bar labels will be appreciated

LivingstoneM
  • 1,088
  • 10
  • 28

1 Answers1

1

As @Mohanasundaram said right in the comments, you can use paste0 with "%" or any other sign to add to your labels like this:

library(tidyverse)
p <-ggplot(fatality, aes(x=year, y=case_fatal)) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_minimal() +
  labs(title="Case Fatality ") +
  geom_text(aes(label=paste0(case_fatal, "%")), vjust=1.6, color="white",
            position = position_dodge(0.9), size=3.5)

p

Output:

enter image description here

Quinten
  • 35,235
  • 5
  • 20
  • 53