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

How to fix "Discrete value supplied to continuous scale" Error in ggplot2

I want to plot the mean abundance data and standard error data which I calculated in Excel as a bar plot in ggplot2. I am getting the error Error: Discrete value supplied to continuous scale when I try to plot my data in gglot2. I have tried using…
OpenSauce
  • 354
  • 2
  • 14
4
votes
1 answer

How to add space between groups of bars in barplot (ggplot)

In R ggplot, I need to make a barplot where bars are grouped together based on a factor called "Mode". There should be spacing between each group of bars. I see in SO that different versions of this problem have come up previously, but the answers…
ben
  • 787
  • 3
  • 16
  • 32
4
votes
1 answer

Reduce space between groups of bars in ggplot2

I haven't been able to remove extra white space flanking groups of bars in geom_plot. I'd like to do what Roland achieves here: Remove space between bars ggplot2 but when I try to implement his solution I get the error "Warning message: geom_bar()…
Emily
  • 470
  • 5
  • 16
4
votes
0 answers

R ggplot geom_bar inaccurate, how to correct?

I've spent quite a bit of time trying to develop a specific geom_bar plot with 2 y-axes (the dual-axes are a work requirement). I've made the plots look acceptable, except there are some inaccuracies with the bar width and bar placement that I can't…
KKL234
  • 367
  • 1
  • 5
  • 23
4
votes
1 answer

ggplot2 order categorical stacked bars by proportions of y-axis

I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest…
user971102
  • 3,005
  • 4
  • 30
  • 37
4
votes
2 answers

How to calculate share per category within a column?

df = data.frame(week = as.factor(rep(c(1, 2), times = 5)), name = as.factor(rep(LETTERS[1:5], times = 2)), count = rpois(n = 10, lambda = 20)) > df week name count 1 1 A 16 2 2 B …
tmhs
  • 998
  • 2
  • 14
  • 27
4
votes
1 answer

geom_errorbar upper for positive mean and lower for negative mean

I would like to plot error bars on my geom_bar plot. I know that you can adjust aes(ymax, ymin) to display only upper or only lower bars. But, I have some negative and positive mean values for which I would like to show the error bars respectively.…
Deep
  • 77
  • 7
4
votes
1 answer

ggplot2: Add label on barplot if position = "fill"

I would like to add %-figures on a filled barplot. Here is the plot with the labels at the wrong places: Here is the dataframe: x0 <- expand.grid(grp = c("G1","G2") , treat = c("T1","T2") , out =…
giordano
  • 2,954
  • 7
  • 35
  • 57
4
votes
2 answers

Overlaying whiskers or error-bar-esque lines on a ggplot

I am creating plots similar to the first example image below, and need plots like the second example below. library(ggplot2) library(scales) # some data data.2015 = data.frame(score = c(-50,20,15,-40,-10,60), area =…
Alex
  • 971
  • 4
  • 15
  • 28
4
votes
1 answer

Add axis text above horizontal geom_bars; justify text flush left

I would like to place axis text above the appropriate horizontal bars in a ggplot2 plot. Below is as far as I have gotten, with the plotting code afterwards. The data is at the bottom of this question. My questions, aside from the ever-present…
lawyeR
  • 7,488
  • 5
  • 33
  • 63
4
votes
1 answer
4
votes
1 answer

ggplot geom_bar can I highlight a bar in different color if value is above a threshold

I use ggplot and geo_bar to produce a plot, results is this: Code # Faceting is a good alternative: ggplot(df.cnts, aes(x=date,y=freq)) + geom_bar(stat="identity") + facet_wrap(~ operator, nrow = 3) + theme(axis.text.x = element_text(angle=90,…
Hugo Koopmans
  • 1,349
  • 1
  • 15
  • 27
4
votes
1 answer

ggplot2 stacked bar chart labels with leader lines

I'm trying to create a labeled stacked bar chart where there is only ever 1 bar. My stacks are not always large enough to fit text so I would like to have leader lines that point to the label just to the right of the stack for the labels that can't…
hailes
  • 125
  • 9
4
votes
3 answers

positioning labels on geom_bar

I am trying to create a horizontal bar chart with category labels using ggplot. I have been able to create the plot without hassles, and can put labels on, however I suffer issues with the formatting. Ultimately I would like to have my label within…
Dan
  • 2,625
  • 5
  • 27
  • 42
4
votes
1 answer

Using ggplot2, how can I create a histogram or bar plot where the last bar is the count of all values greater than some number?

I would like to plot a histogram of my data to show its distribution, but I have a few outliers that are really high compared to most of the values, which are < 1.00. Rather than having one or two bars scrunched up at the far left and then nothing…
shirewoman2
  • 1,842
  • 4
  • 19
  • 31