Add two x axis labels on geom_bar

24 views Asked by At

I have been checking some similar cases, but have not able to find a answer, so please your help on this. Here is my data frame:

cities = c("city100", "city152", "city163", "city174", "city185", "city196") population = c(108934,157906,567124,127012,267345,123740) df <- data.frame(cities=cities, population=population)

My current plot is this

ggplot(df,aes(x= reorder(cities, -population), y=population, fill=cities)) +
    geom_text(aes(label = scales::comma(population)),hjust =0,size=2.5, angle = 90) +
    scale_y_continuous(labels = scales::label_number_si(), limits = c(0,740000))  +
    ggtitle("City Population") +
    theme(plot.title = element_text(color="blue", size=15, hjust =0.5, face="bold.italic")) +
    geom_bar(stat = "identity") +
    theme(axis.text.x = element_text(size=7, angle=90,hjust=0.95,vjust=0.2) ) +
    labs(x = "Cities", y ="Population", fill = "cities")

I getting this graph. enter image description here

But I'd like to get something like this enter image description here

Because the additional x axis title can give info about the position of the city by population.

Some recommendations about how to get the graph I need. Any help will be very useful

0

There are 0 answers