How to arrange y axis in bar chart using ggplot2

Prafulla

I have a following dataframe and I'am trying to plot bar chart.

country <- c('AUD','USD','GBP','ROW','EUR')
count <- c(58, 28, 8, 4, 2)
data <- data.frame(country, count)

    ggplot(data = data , aes(x = 'COUNTRY', y = reorder(count, -count), fill = country))+
  geom_bar(stat = "identity")+ 
  xlab("COUNTRY")+
  ylab("TOTAL")+
  theme_minimal()+
  geom_text(aes(label = country), vjust = -0.5, size = 3)+
  scale_fill_brewer(palette="Paired")+
  theme(legend.position = "bottom",
        legend.title = element_blank())

Plot generated by this code does not have axis and point labels in order. It generates below plot.

enter image description here

I need a help to re-arrange this axis and count labels.

Christoph Wolk

It's not quite clear to me what you want the output to look like. Would something like this be ok?

ggplot(data = data , aes(x = 'COUNTRY', y = count, 
                         fill = reorder(country, count)))+
  geom_bar(stat = "identity")+ 
  xlab("COUNTRY")+
  ylab("TOTAL")+
  theme_minimal()+
  geom_text(aes(label = sprintf("%s (%d)", country, count), 
                y = cumsum(count) - 0.5*count), size = 3)+
  scale_fill_brewer(palette="Paired")+
  theme(legend.position = "bottom",
        legend.title = element_blank())

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

R: ggplot stacked bar chart with counts on y axis but percentage as label

Combining Bar and Line chart (double axis) in ggplot2

ggplot2 bar chart sign on y-axis

how to set two x axis and two y axis using ggplot2

Manually change order of y axis items on complicated stacked bar chart in ggplot2

How to format a radar chart in R with axis labels and rotation using ggplot2

How do to conditionally bold y axis text in gantt chart using ggplot2

How to add a point on the y-intercept (y-axis) using ggplot2

Grouped stacked bar chart in ggplot2 where each stack corresponds to its y axis value

How to create a grouped bar chart (by month and year) on the x-axis and values on the y-axis using matplotlib.pyplot?

How to add Thousand separator in both axis of a 2-y axis chart in R using ggplot2

ggplot2: incorrect values on y-axis when using bar plot and stat = 'identity'

ggplot2: negative bar chart with dual x axis

ggplot2 bar chart gives weird y axis

How to Arrange the x axis on a Plotly Bar Chart with R

How to adjust the Y Axis maximum value on a bar chart in LibreOffice Calc

How to display 0 value in a bar chart using ggplot2

In Highcharts, how to reverse y-axis under "Bar" chart type?

Grouped bar chart using ggplot2

How to add a 2nd Y-axis on a grouped bar chart using Altair? and sort the bar using value of one of the column from the data

Breaking y-axis in ggplot2 with geom_bar

How to create a bar chart with a fixed y-axis value in Shiny?

How to modify the limits of y axis of a stacked bar chart in polar coordinates using ggplot2?

Can get ggplot2 bar chart to display direct values for Y axis?

How to plot a chart with dual Y, both are bar plot with ggplot2?

How to make a bar-chart by using two variables on x-axis and a grouped variable on y-axis?

Plotting a Bar chart using ggplot2

R & ggplot2: 100% geom_bar + geom_line for average using secondary y axis

How to remove y-axis from grouped bar chart

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive