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

ggplot2 (Barplot + LinePlot) - Dual Y axis

I am having a really hard time recreating an excel example with ggplot2. I have tried numerous examples but for some reason I cannot reach my desired result. Can someone please have a look at my example? df <- structure(list(OccuranceCT = c(4825,…
Cosmin
  • 565
  • 1
  • 8
  • 33
7
votes
0 answers

label gets cut on ggplot2 bar plot

I created a ggplot2 bar plot and added a label, with the bar y-value, above the bar. d <- data.frame( Ano=2000+5*0:10, Populacao =c(6.1,6.5,6.9,7.3,7.7,8.0,8.3,8.6,8.9,9.1,9.3) ) d %>% ggplot(aes(x=Ano, y=Populacao)) +…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
7
votes
5 answers

ggplot2: geom_bar with group, position_dodge and fill

I am trying to generate a barplot such that the x-axes is by patient with each patient having multiple samples. So for instance (using the mtcars data as a template of what the data would look like): library("ggplot2") ggplot(mtcars, aes(x =…
TinyHeero
  • 580
  • 1
  • 4
  • 18
6
votes
2 answers

How to use stat="count" to label a bar chart with counts or percentages in ggplot2?

I'm trying to produce a stacked column chart with data labels. I'm able to produce the chart, but was unable to find a way to input data labels. I have tried geom_text() but it keeps asking me to input a y label (which if you see the ggplot code is…
nike.96
  • 67
  • 1
  • 1
  • 5
6
votes
1 answer

geom_bar() make bars different widths and completely overlap

I have some data that captures percentages of two different groups over multiple time periods. df <- structure(list(period = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("FY18 Q4", "FY19 Q1", "FY19 Q2", "FY19 Q3", "FY19 Q4"),…
CurtLH
  • 2,329
  • 4
  • 41
  • 64
6
votes
1 answer

manipulate delineation of geom_bar and coord_polar in ggplot2 r

I am building a chart of concentric circles using polar_coord in ggplot and I need to get rid of a specific line. Here's the code and the plot: df <- data.frame(A=letters[1:12], B=c(rep("Dim_1",4),rep("Dim_2",4),rep("Dim_3",4)), …
NBK
  • 887
  • 9
  • 20
6
votes
0 answers

R ggplot, geom_text to round labels within the label command?

Right now I can get labels of the fill value above by bars in ggplot geom_bar. But what I can't seem to do is change the number of decimal places of the label. Right now it has 9 decimal places and I only want 2. I have tried using round() and…
Natalie
  • 91
  • 1
  • 1
  • 7
6
votes
1 answer

Adding group mean lines to geom_bar plot and including in legend

I want to be able to create a bar graph which shows also shows the mean value for bars in each group. AND shows the mean bar in the legend. I have been able to get this graph Bar chart with means using the code below, which is fine, but I would like…
ekmz
  • 93
  • 1
  • 7
6
votes
1 answer

scale_fill_manual is not working in geom_bar

I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example: library(ggplot2) library(dplyr) iris %>%…
Roberto
  • 93
  • 1
  • 1
  • 4
6
votes
2 answers

ggplot2: Change color for each facet in bar chart

I have a faceted bar chart done with ggplot2 with this code: ggplot(data_long, aes(x=region, y=wert)) + geom_bar(aes(fill = kat ), position = "dodge", width=.5, stat="identity") + labs(y = "Wähleranteil [ % ]", x = NULL, fill = NULL) + facet_grid(.…
Mario
  • 2,393
  • 2
  • 17
  • 37
6
votes
3 answers

How to set Bin Width With geom_bar stat="identity" in a time Series plot?

I would like to plot a time series using bar charts and have the Bin Width set to 0.9. I cannot seem to be able to do that however. I have searched around but could not find anything helpful so far. Is this a limitation if the stat="identity ? Here…
Riad
  • 953
  • 3
  • 13
  • 23
6
votes
3 answers

Specific spaces between bars in a barplot - ggplot2 - R

I have a simple bargraph like the following a<-data.frame(x=c("total","male","female","low education", "mid education","high education","working","not working"), …
6
votes
1 answer

R - ggplot - Rounded extremity for geom_bar

This is a simple example of what my barplot look like : x <- data.frame(aa=c(0.2,0.6,0.1), dd = c(1,2,3)) x <- melt(x, "dd") y <- data.frame(bb=c(0.4,0.5), dd = c(1,2)) y <- melt(y, "dd") z <- data.frame(cc=c(0.5,0.25,0.1,0.05), dd = c(1,2,3,4)) z…
R_SOF
  • 268
  • 1
  • 7
6
votes
3 answers

ggplot: Showing x-axis line for each facet plot

I have created a facet plot using ggplot which has 4 rows and 1 column with this code: ggplot(data=c, aes(x=Time, y=X.mean, fill = Site, width=.1)) + geom_bar(stat="identity", position=position_dodge(), width=0.5,colour="black", …
user2553008
  • 61
  • 1
  • 3
6
votes
1 answer

Define different label size by category in geom_bar

I am trying to plot a stacked barchart using geom_bar and label each category with its value within the barchart. Because some categories have small values, the height of the corresponding segment of the barchart is sometimes small. So, I am trying…
user2162057
1 2
3
68 69