Georgia Bingham
Georgia Bingham

Reputation: 1

gg-plot isnt producing bars on the Bar chart

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.

Upvotes: 0

Views: 99

Answers (1)

Shawn Hemelstrand
Shawn Hemelstrand

Reputation: 3238

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

Upvotes: 1

Related Questions