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
15
votes
1 answer

Put labels over negative and positive geom_bar

I'd like to visualize a data using bar chart and ggplot. I have the data below, when I want to vis this data the text for negative values are not showing below the Bar . dat <- read.table(text = "sample Types Value sample1 A -36 sample2 B …
Tamra.y
  • 235
  • 3
  • 9
15
votes
3 answers

ggplot2: Setting geom_bar baseline to 1 instead of zero

I'm trying to make a bar graph (with geom_bar) of ratios, and would like to set the x-axis at y=1. Therefore, ratios <1 would be below the axis and ratios >1 would be above the axis. I can do something similar with geom_point: ggplot(data,…
CYT
  • 189
  • 1
  • 1
  • 4
14
votes
2 answers

Bars in geom_bar have unwanted different widths when using facet_wrap

I can'd find a solution for the following problem(s). I would appreciate some help a lot! The following code produces bar charts using facet. However, due to "extra space" ggplot2 has in some groups it makes the bars much wider, even if I specify a…
Moritz Schmid
  • 395
  • 6
  • 16
14
votes
2 answers

How to make variable bar widths in ggplot2 not overlap or gap

geom_bar seems to work best when it has fixed width bars - even the spaces between bars seem to be determined by width, according to the documentation. When you have variable widths, however, it does not respond as I would expect, leading to…
RobinLovelace
  • 4,799
  • 6
  • 29
  • 40
13
votes
3 answers

Order categorical data in a stacked bar plot with ggplot2

I have a matrix with the following entries: MilDis <- data.frame( hhDomMil = c( "HED", "ETB", "HED", "ETB", "PER", "BUM", "EXP", "TRA", "TRA", "PMA", "MAT", "MAT", "KON", "ETB", "PMA", "PMA", "HED", "BUM", "BUM", "HED", "PMA", "PMA", …
Dominik
  • 2,753
  • 7
  • 28
  • 32
13
votes
4 answers

Creating a vertical color gradient for a geom_bar plot

I have searched and searched, but I cant seem to find an elegant way of doing this! I have a dataset Data consisting of Data$x (dates) and Data$y (numbers from 0 to 1) I want to plot them in a bar-chart: ggplot(Data) + geom_bar(aes(x = x, y = y,…
13
votes
1 answer

Generate paired stacked bar charts in ggplot (using position_dodge only on some variables)

I'm hoping to use ggplot2 to generate a set of stacked bars in pairs, much like this: With the following example data: df <- expand.grid(name = c("oak","birch","cedar"), sample = c("one","two"), type =…
canary_in_the_data_mine
  • 2,193
  • 2
  • 24
  • 28
12
votes
2 answers

Alpha aesthetic shows arrow's skeleton instead of plain shape - how to prevent it?

I'm aiming at building a bar plot with arrows at the end of bars. I went for geom_segment with arrow defined. I want to map one column onto transparency, but the alpha aesthetic doesn't seem to work fine with arrow object. Here's the code…
jakes
  • 1,964
  • 3
  • 18
  • 50
11
votes
2 answers

geom_bar from min to max data value

I am not sure if geom_bar is able (probably I'm not) to create the plot I need with geom_bar. I want a bar plot but not starting from 0, I have a minimum and maximum value that are to be the start and end points of each bar. Desired output looks…
pacomet
  • 5,011
  • 12
  • 59
  • 111
10
votes
2 answers

ggplot2: reorder bars from highest to lowest in each facet

In the df below, I want to reorder bars from highest to lowest in each facet I tried df <- df %>% tidyr::gather("var", "value", 2:4) ggplot(df, aes (x = reorder(id, -value), y = value, fill = id))+ geom_bar(stat="identity")+facet_wrap(~var, ncol…
shiny
  • 3,380
  • 9
  • 42
  • 79
10
votes
3 answers

Constant width in ggplot barplots

How to make the width of bars and spaces between them fixed for several barplots using ggplot, having different number of bars on each plot? Here is a failed try: m <- data.frame(x=1:10,y=runif(10)) ggplot(m, aes(x,y)) +…
Ali
  • 9,440
  • 12
  • 62
  • 92
8
votes
1 answer

Move axis labels in between plot and facet strip

I am trying to move the facet strip to the far left of my plot, so that the labels sit adjacent to the bars, and the grouping strips sit to their left (see my example below). I assume this must be done with Grobs, but I have little experience with…
Alex
  • 971
  • 4
  • 15
  • 28
8
votes
2 answers

R ggplot geom_bar Error: Discrete value supplied to continuous scale

I have proportion response data for 4 experimental groups, with 2 different statistics computed for each group. I want the following figure (which I can achieve): I obtain this figure with the following…
Chris Z.
  • 425
  • 1
  • 5
  • 6
8
votes
1 answer

ggplot2, geom_bar, dodge, order of bars

I'd like to have ordered bars in dodge geom_bar. Do you know how to deal with it? My code: ttt <- data.frame(typ=rep(c("main", "boks", "cuk"), 2), klaster=rep(c("1", "2"), 3), ile=c(5, 4, 6, 1, 8, 7)) ggplot()+ …
Marta
  • 3,032
  • 3
  • 17
  • 34
7
votes
3 answers

order and fill with 2 different variables geom_bar ggplot2 R

I have a question concerning the fill field in geom_bar of the ggplot2 package. I would like to fill my geom_bar with a variable (in the next example the variable is called var_fill) but order the geom_plot with another variable (called clarity in…
antuki
  • 236
  • 2
  • 9
1
2
3
68 69