0

I have used the following code

ggplot(IncomeGroup_count, 
  aes(x=Income_Group, 
      y= Percentage, 
      colour = 'lightblue'))

But the only thing it produces is the x and y axis with no bars.

DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25
  • 1
    You need to add a geom (e.g. geom_point() for points or geom_line() for lines) for ggplot() to actually present anything – Thomas J. Brailey Nov 03 '22 at 15:47
  • For bars you'd want `geom_bar()`. If you want us to provide a full code example of how to get bars on your graph then you'd have to provide a minimum reproducible example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Harrison Jones Nov 03 '22 at 15:49

1 Answers1

1

It looks like you are missing the geom_bar function. Typically ggplot works as the base function for fitting whatever data you are using and then the geom functions "draw" the plot using that data. Here I have constructed a bar plot using data in R since you have not supplied your own data in your question.

#### Load Library ####
library(tidyverse)

#### Plot ####
airquality %>% 
  ggplot(aes(x=is.na(Ozone)))+
  geom_bar()

Which gives you this bare bones bar plot. It takes the NA values from the airquality dataset, then draws bars thereafter plotting the NA values by "TRUE" for NA and "FALSE" for not NA:

enter image description here

Edit

Again it's difficult to guess what is going wrong if you don't share your data, so I'm assuming based off your comments below that you are trying to plot y explicitly as a count. As suggested in the comments, geom_col may be better for this. Using a different example from the same dataset:

airquality %>% 
  group_by(Month) %>% 
  summarise(Mean_Ozone = mean(Ozone, na.rm=T)) %>% 
  ggplot(aes(x=Month,
             y=Mean_Ozone))+
  geom_col()

You get this:

enter image description here

Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30