Isuru Ovin
Isuru Ovin

Reputation: 11

Drawing a bar chart using bin sizes

Arrival_Frequency     Total_Arrival
           0-1              2633586
           2-4               223079
           4-7                 5281
           7+                  1718

How to get bar plot for this. If use normal geom_bar() it gives the count not the total.

Upvotes: 1

Views: 39

Answers (1)

UseR10085
UseR10085

Reputation: 8176

Do you want this?

library(scales)
library(tidyverse)

ggplot(df, aes(x=Arrival_Frequency, y=Total_Arrival))+ 
  geom_bar(position=position_dodge(), stat="identity") + 
  scale_y_continuous(labels = label_number()) +
  ylab("Total Arrival") + xlab("Arrival Frequency")

enter image description here

Your values are wide apart. So, you can think of transforming the values like

ggplot(df, aes(x=Arrival_Frequency, y=Total_Arrival))+ 
  geom_col() + 
  scale_y_continuous(trans = "log", labels = label_number()) +
  ylab("log (Total Arrival)") + xlab("Arrival Frequency")

enter image description here

Upvotes: 1

Related Questions