Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My bar chart only prints a single bar from my data

When using the following data and code my bar char only prints 1 bar, any idea on how to fix this?

life_bar
# A tibble: 6 Ă— 2
  Continent                mn
  <chr>                 <dbl>
1 Africa                 41.1
2 Americas               19.5
3 Eastern Mediterranean  47.0
4 Europe                 15.6
5 South-East Asia        37.7
6 Western Pacific        16.4

Code used;

ggplot(life_bar, aes(x = 'mn')) +
geom_bar(fill = 'green', col = 'black')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to specify both x and y variables. x should be Continent and y should be mn. You don’t quote the column names.

Also when using geom_bar() you need to specify how the values should be aggregated – in your case geom_bar(stat = "identity"). You can avoid that by using geom_col().

ggplot(life_bar, aes(x = Continent, y = mn)) + 
geom_col()

There’s lots of built-in help in R e.g. ?geom_bar and extensive online help too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading