Questions tagged [geom-bar]

`geom_bar` is the geometric object description for creating a barplot in `ggplot2`

geom_bar is the geometric object description for creating a barplot in ggplot2, which is an actively maintained open-source chart-drawing library for R. is written by Hadley Wickham and based upon the principles of "Grammar of Graphics".

Resources for using geom_bar:

1029 questions
2
votes
2 answers

Add gradient color within groups in ggplot2

I need help in order to add colors to ggplot objects (specificaly geom_bar). Here is my data Names Family Groups Values H.sapiens A G1 2 H.erectus A G1 6 H.erectus B G2…
chippycentra
  • 3,396
  • 1
  • 6
  • 24
2
votes
1 answer

Back-to-back/population plot in ggplot2

I am attempting to produce a back-to-back bar plot (aka population pyramid plot) using ggplot2. Here is an example: There are multiple examples of creating these plots on S/O (e.g., here, here and here), but none of the solutions offered in these…
jmogil
  • 143
  • 8
2
votes
2 answers

Adding specific labels to a the top of columns on geom_bar in R

I have a database with a sample im working on. Im trying to get the code to add all the earnings for each variable (12 variables) and then display on top of each column an abbreviated version of the number because it is in the billions and it is two…
2
votes
1 answer

Can you combine a geom_bar pie over a geom_point plot in R?

Is there a way to plot geom_pie over a geom_point plot? with a shared Variable (here: Location) I have seen people do pies over maps plotting pie graphs on map in ggplot But I was wondering if there is some package or function which allows you to do…
Ecg
  • 908
  • 1
  • 10
  • 28
2
votes
1 answer

R ggplot geom_bar count number of values by groups

I tried this code without faceting, it works. I want to add counts on each bar and use facets in my plot, it brokes. I managed to make it close to what I want, like this: mtcars %>% group_by(gear, am, vs) %>% summarize(hp_sum = sum(hp), hp = hp)…
Shujun Ou
  • 31
  • 1
  • 4
2
votes
1 answer

Error message of missing values while plotting facet_grid bar plot

I'm making a facet grid bar plot using ggplot2. I keep getting the error message "Removed 15 rows containing missing values (geom_bar)" when there's no missing values in my dataset. Here's a reproducible example where I'm plotting the likeability of…
jo_
  • 677
  • 2
  • 11
2
votes
1 answer

Why is my bar plot showing an empty output?

I am trying to create a simple bar plot but the output is empty (picture attached) for some reason. #test graph test1 <- ggplot(leg19.votosglobais, aes(partido, votos), geom_bar(stat = "identity")) The dataset is this: > leg19.votosglobais …
dt00370
  • 53
  • 4
2
votes
1 answer

How to add multiple legend when we use multiple geom_bar?

Here is my data t time_granularity N V2 V3 V4 1: 2019-03-07 06:00:00 3445 874 1560 2569 2: 2019-03-07 06:15:00 5871 1366 2550 3920 3: 2019-03-07 06:30:00 9790 2157 3831 5615 4: 2019-03-07 06:45:00 13809 3182 5497 …
XinDou
  • 37
  • 3
2
votes
1 answer

Graph stack bar for multiple variables with wrong percentages

I am trying to get a graph stack bar for multiples variables to display percentages for each level in each variable, example: Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Country <- c(rep(c("Country A", "Country B", "Country C", "Country…
2
votes
2 answers

R: Display character or categories on a stack bar

I am trying to add the category and percent to each level in a stack bar, example: Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Data <- data.frame( Category) p= ggplot(Data,aes(x=factor(""),fill=factor(Category)))+ …
2
votes
3 answers

How to use conditional statement to colour barplot

I'm trying to colour geom_bar according to the number of the sample ifelse(total > 90, "#FC2D00", "#008EFC"). In other words, if the total > 90, the bar should be red but total < 90, it should be blue. type = c("aa", "bb", "cc") total = c(110, 90,…
Sam
  • 309
  • 2
  • 10
2
votes
3 answers

Add a cumulative frequency to a bar chart in ggplot

I would like to add a cumulative frequency to a bar chart but I have difficulties. Here is the code of the bar chart graph: GZ1 <- ggplot(data = ZOO_long2) + geom_bar(aes(x=interaction(Family,Group),fill = Group),width = 0.7, color = "black", alpha…
C. Guff
  • 418
  • 3
  • 18
2
votes
1 answer

geom_bar grouped data with geom_point color based on values

I would like to add geom_point showing value of sect to my grouped geom_bar showing value of perc with point colour based on conditional data My data is like this: ```structure(list(year = c(2019, 2019, 2019, 2018, 2018, 2018, 2017, 2017, 2017,…
adame
  • 137
  • 7
2
votes
1 answer

How can I animate geom_bar to "add data" using a filter function?

Ok, we all know this is not my real data or question, but, for the sake of a reproducible example... Let's say that I'm trying to get enough flowers for my daughter's wedding. My friend Anna has 25 plants of each species in the iris dataset at her…
Nova
  • 5,423
  • 2
  • 42
  • 62
2
votes
1 answer

Width of bars in ggplot2 with many groups

I tried to reproduce the answer given by Roman in this post: The same width of the bars in geom_bar(position = "dodge") but I couldnot fix my problem. When bars have the same width, the distance between the groups are too big. Same problem when I…
Matías
  • 21
  • 3