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

Add image background to ggplot barplot so that image is only visible inside of bars

I would like to create a barplot in R using ggplot2 so that the bars are transparent, allowing a background image to be visible, while the rest of the plot is opaque and covering the background image. I can add an image to the background, as…
MaggiB
  • 53
  • 3
5
votes
1 answer

Plot table function objects with ggplot?

I've got this data: table(main$Sex1,main$District) Bahawalnagar Barkhan Chiniot Faisalabad Ghotki Female 37 16 26 97 46 Male 25 19 15 20 25 I can plot it with…
Ali Zohaib
  • 109
  • 1
  • 9
5
votes
1 answer

Plot hline at mean with geom_bar and stat="identity"

I have a barplot where the exact bar heights are in the dataframe. df <- data.frame(x=LETTERS[1:6], y=c(1:6, 1:6 + 1), g=rep(x = c("a", "b"), each=6)) ggplot(df, aes(x=x, y=y, fill=g, group=g)) + geom_bar(stat="identity", position="dodge") Now…
c0bra
  • 1,031
  • 5
  • 22
5
votes
1 answer

ggplot2 problems with using ...prop... and grouping bar graph by another category

StudentData <- data.frame(gender = sample( c("male","female"), 100, replace=TRUE), degree = sample( c("Associates", "Masters", "PhD"), 100, replace=TRUE), category = sample( c("Audit", "Credit"), 100, replace=TRUE)) In…
Syrah.Sharpe
  • 103
  • 1
  • 8
5
votes
2 answers

ggplot2: geom_bar with custom y limits

I want to draw a bar chart with ggplot2 along with custom y limits. Type <- LETTERS[1:5] Y <- c(99, 99.5, 99.0, 98.8, 98.5) df <- data.frame(Type, Y) The following code works fine for bar chart: library(ggplot2) ggplot(data = df, mapping =…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
5
votes
1 answer

geom_bar ggplot2 stacked, grouped bar plot with positive and negative values - pyramid plot

I don't even know how to describe the plot I am trying to generate properly, which is not a great start. I will first show you my data, and then try to explain / show images that have elements of it. My data: strain condition count.up…
mdelow
  • 65
  • 1
  • 2
  • 10
5
votes
2 answers

geom_bar + geom_line: with different y-axis scale?

Is there any way to plot geom_bar with geom_line like the following chart. I have come up with the two separate charts. How to combine them with two different axes on the left and right sides respectively. library(ggplot2) temp =…
John
  • 1,779
  • 3
  • 25
  • 53
5
votes
1 answer

Automatically resize bars in ggplot for uniformity across several graphs R

I generate several bars graphs in a loop, and they all resize according to the output size (assume from plot/device size?) rather than according to the bar size. This means that plots with two bars have fat bars, and plots with, say, 6 bars, have…
Alex
  • 971
  • 4
  • 15
  • 28
5
votes
1 answer

ggplot2: geom_bar stacked barplot, specify bar outline color

I am trying to figure out how to specify the outline color on a stacked barplot in ggplot2. In the below code I specify color="green", which gives a green outline to each of the bars. I would like to specify a different outline color for each bar…
CAT
  • 73
  • 1
  • 5
4
votes
2 answers

Connect stack bar charts with multiple groups with lines or segments using ggplot 2

I am conducting a study of a number of patients with a disease, and using an ordinal scale assessment of functional status at 3 different time points. I want to connect multiple groups in stacked bar charts across these time points. I looked at…
XFrost
  • 109
  • 4
4
votes
2 answers

Connect observations (dots and lines) without using ggpaired

I created a bar chart using geom_bar with "Group" on the x-axis (Female, Male), and "Values" on the y-axis. Group is further subdivided into "Session" such that there is "Session 1" and "Session 2" for both Male and Female (i.e. four bars in…
Grace
  • 55
  • 8
4
votes
1 answer

Percentages for geom_text in stacked barplot with counts

I want to have a stacked barplot with percentages in it based on counts. I have almost reached what I want but every value in the text is 100% instead of the real percentage ... I think there is one small mistake in my code but I can not find…
TobiSonne
  • 1,044
  • 7
  • 22
4
votes
1 answer

Removing the bottom border for borders in geom_bar

I'm looking for a way to remove the non-overlapping bottom border when added in geom_bar. I don't want to use an option like geom_hline(yintercept = 0, colour = "white"), as nitpicky as it sounds as it covers the original bar's single line of…
Nautica
  • 2,004
  • 1
  • 12
  • 35
4
votes
2 answers

ggplot grouped geom_bar - adding labels of factor categories to the x-axis label

I have this R code to produce a vertical grouped bar chart: library(ggplot2) exampledf <- data.frame( subchar = c("facebook", "twitter", "snapchat", "male", "female"), superchar = c("social media", "social media", "social media", "gender",…
elynagh
  • 85
  • 7
4
votes
1 answer

Is there a possibility to combine position_stack and nudge_x in a stacked bar chart in ggplot2?

I want to add labels to a stacked bar chart to achieve something like this: The goal is simple: I need to show market shares and changes versus previous year in the same graph. In theory, I would just add "nudge_x=0.5," to geom_text in the code but…