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
4
votes
2 answers

ggplot stacked bar ordering fails with unknown function desc

I'm trying to change the order of the levels in my stacked bar plot (the order it stacks the fill levels). In the ggplot documentation it show this as being straight-forward with: # Use the order aesthetic to change stacking order of bar charts w <-…
Dane Collins
  • 43
  • 1
  • 3
4
votes
1 answer

geom_bar(): stacked and dodged combined

I seek advice on ggplot2::geom_bar(). My data contains the categories "A", "B", "Z". I want A, B as stacked bar, and Z as dodged bar next to the A, B bar. # sample data A = c(3, 4, 3, 5) B = c(2, 2, 1, 4) Z = c(1, 2, 1, 2) R = c(-2, -1, -3, 0) S =…
user3817704
  • 401
  • 1
  • 5
  • 12
4
votes
2 answers

In ggplot2, can borders of bars be changed on only one side? (color, thickness)

I know, 3D Barcharts are a sin. But i´m asked to do them and as a trade-off i suggested to only make a border with a slightly darker color than the bar´s on the top and the right side of the bar. Like that, the bars would have some kind of "shadow"…
SEMson
  • 1,285
  • 3
  • 20
  • 25
3
votes
1 answer

How do I create a facet_wrap diagram using geom_bar that includes all the variables and their bars in grey color and specific variable in other color?

I have a dataframe: df1 <- data.frame(place = c("a", "a", "b", "b", "c", "c", "d", "d", "e", "e", "f", "f", "g", "g", "h", "h", "i", "i", "j", "j", "k", "k", "l", "l", "m", "m", "n", "n", "o", "o",…
knick
  • 37
  • 4
3
votes
2 answers

ggplot dodged bar chart: arrange bars by y-value per group

I need to plot a bar chart in R where the order of the bars is exactly like in the data_frame below, i.e. I need group 1 on the left, 2 in the middle and 3 on the right. But: I also need the bars to be arranged descending by score within the three…
Vanessa
  • 117
  • 6
3
votes
1 answer

How can I show legend of multiple layers (geom_point and geom_bar)?

I have two data sets that I want to combine into one plot, one as a barplot (2 groups) and one as a point-line plot (1 group). I've managed to combine the plots and show the legend for the barplot, but whenever I try to show the legend for the…
Keni
  • 63
  • 5
3
votes
1 answer

Can I add grouping line labels above my ggplot bar/column chart?

I'm interested in adding grouping labels above my ggplot bar charts. This feature exists for data visualizations such as phylogenetic trees (in ggtree), but I haven't found a way to do it in ggplot. I've tried toying around with geom_text, and…
3
votes
1 answer

Plotting bar charts to a map in R ggplot2

I would like to add bar charts to a map in ggplot2. Similar questions exist (this one and this one) but their answers involve ggsubplot, which is deprecated. geom_scatterpie() provides a way to do this with pie charts (example 1 but also see example…
BonnieM
  • 191
  • 1
  • 13
3
votes
1 answer

Why this code is not right statically in ggplot to get percentage in y-axis?

I have this data, and I want to get percentage in y-axis. structure(list(sb_1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("0", "x"), class = "factor"), sb_2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, …
Ali Roghani
  • 495
  • 2
  • 7
3
votes
1 answer

What are all the positions for geom_bar() and geom_col()?

I've looked in an infinity of places, but none of them actually put all the positions available for these two geoms. I know there are stack (to put one on top of the other), dodge (to make little clusters with each group side-by-side), identity (to…
Érico Patto
  • 1,015
  • 4
  • 18
3
votes
2 answers

ggplot: plot mean values instead of counts

I have the following sample data, which describe how long (duration) each respondent in my questionnaire needed to answer each question (question) and in which week the question was answered (there were several waves of the same questionnaire) n <-…
D. Studer
  • 1,711
  • 1
  • 16
  • 35
3
votes
3 answers

How to drop x value from ggplot with discrete axis?

This may be something that is an easy fix. I am creating a new dashboard in shiny and it's been asked by my company that all plots be ordered by a list. So naturally I created a list and used scale_x_discrete(limits = list). However, what is being…
fullera
  • 164
  • 6
3
votes
1 answer

Preserve location of missing columns in combined bar plot

A very commonly posted issue is to preserve the width of bars when there is a missing column in ggplot (e.g. 1, 2. What I need in addition to this fix is to also preserve the relative location of the missing bars (i.e. the gaps should be where the…
Andre
  • 101
  • 4
3
votes
2 answers

How to show percentages in stacked column with ggplot geom_bar?

I'm trying to add percentage labels in a stacked bar chart. What can I add to my geom_bar to show the percentage labels inside stacked bars? This is my data: myresults=data.frame( …
Hyeonjeong
  • 31
  • 1
  • 5
3
votes
1 answer

Format internal lines of stacked geom_bar inside geom_tile ggplot2

this may relevant to this question: format-internal-lines-of-a-stacked-geom-bar-ggplot, but I still can not solve it since I am still beginner. I have many stacked bar for this plot, here is just sample data. I just want to keep external border and…
mjberlin15
  • 147
  • 1
  • 10