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

How to combine geom_bar, geom_point, and geom_line into one figure?

I am trying to visualize continuous data points across two Time points (pre and post intervention) with three parallel Conditions (CET, RES, END), and Response to intervention (High or Low, i.e., CET_Hi, CET_Lo, etc) I'd like to create a bar graph…
bshamim
  • 33
  • 1
  • 4
3
votes
1 answer

plot slightly separated in-group bars with ggplot2 geom_bar()

Is there a way to have a little separation between each group bars made with grouped bar_plot()? Like having a bigger distance between different groups and small distance inside group bars, but not sticked one another. Here the whole code: ### my DF…
cccnrc
  • 1,195
  • 11
  • 27
3
votes
1 answer

ggplot2: bar plot of raw data with frame around aggregated

I'm trying to create a stacked bar plot from raw data, where each set of factor variables potentially has multiple entries and the y-values should be the sum of all such entries. Doing a normal geom_bar at first looks fine, but it seems to plot each…
3
votes
1 answer

A single bar is misplaced in a barplot (ggplot2)

I'm making a 2-panel barplot, but there seems to be a problem with a single bar that is out of its place. It is the bar in the upper part of the right panel. It is filled as TR but it occupies the place of the TL. The data is: DATA2=structure(list(A…
3
votes
1 answer

adjusting position of text above an error bar in ggplot

I have the following data frame: df <- structure(list(Gender = c("M", "M", "M", "M", "F", "F", "F", "F"), HGGroup = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("Low: \n F: <11.5, M: <12.5", "Medium: \n F: > 11.5 & < 13, M: >12.5 & <…
Omry Atia
  • 2,411
  • 2
  • 14
  • 27
3
votes
0 answers

ggplot2: Stacked bar and legend on the top

I am trying to plot my data using stacked bar plot. I want to put the legend on the top of the plot for aesthetics reasons. However, when I do so the order of the does not match the order of the stacked bars. I tried to change it in a number of…
degopwn
  • 507
  • 1
  • 5
  • 14
3
votes
2 answers

ggplot: Add different lines in each facet of geom_bar

This questions is following my previous question: How to ordering bars within all facets? I want to add different lines in each facet of my geom_bar. I used the geom_hline function, but all lines are added in all facets! My code: i <-…
Ph.D.Student
  • 704
  • 6
  • 27
3
votes
0 answers

Complicated multiple bar and ribbon/area chart of boarding/alighting bus passenger in ggplo2 [R]

I am trying to produce a bar chart combining ribbon/area chart which illustrates boarding/alighting passengers of BRT/MRT lines at each station as well as sectional passenger volume along a corridor by direction. Initial data frame is shown…
HSJ
  • 687
  • 6
  • 16
3
votes
1 answer

how to add points to stacked barplots

I would like to add points (the variable nb species) on my already existing chart. I tried to add the points with the function geom_point but unfortunately i have this error: "Discrete value supplied to continuous scale". You will find below my…
Elodie P.
  • 73
  • 1
  • 4
3
votes
2 answers

What is the "N = 1" box in my R geom_bar legend, and how do I remove?

These are the data: structure(list(Group.1 = c((name list) ), Group.2 = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Radio", "Video",…
3
votes
1 answer

Put x labels on top of bars AND justify it towards the x axis

I am trying to position x labels on a geom_bar so that they are vertical, on top of the bars, and aligned to the bottom of the bars. I have gotten the first two, but not the last. data(mpg) mpg <- mpg This justifies the text the way I want it…
Stonecraft
  • 860
  • 1
  • 12
  • 30
3
votes
1 answer

Reorder grouped bar plot within facets

My third question today, learning a lot thanks all. I am trying to reorder the bar groups within each facet by the curr.data$Gap variable. The Gap is the difference between the bars for each y label, and I need the order within each facet to go from…
Alex
  • 971
  • 4
  • 15
  • 28
3
votes
1 answer

How to differentiate different groups in bar plot by using R-ggplot2 except using fill-in colors

set.seed(1221) df <- data.frame(group = rep(LETTERS[1:12], 3), outcome = c(runif(12, 1, 5), runif(12, 5, 10), runif(12, 5, 8) ), trt = rep(c("H", "M", "L"), each=12) ) ggplot(df, aes(x=trt, y=outcome, fill=group)…
Bin
  • 517
  • 1
  • 4
  • 15
3
votes
1 answer

Karyogram and SNP with ggplot2 (geom_path, geom_bar, ggbio)

I want to plot a karyogram with SNP markers. It works with function segments but I want to use ggplot2 package to display an elegant graphic. ggbio: I checked the package ggbio with the function layout_karyogram but the chromosomes are plotted in…
user7634238
3
votes
2 answers

Sorting bars in a bar chart with ggplot2

First time asking here so forgive me if I'm not clear enough. So far I have seen many replies to similar questions, which explain how to sort bars by some field of a data frame; but I've been not able to find how to sort them by the default stat…
Javi
  • 159
  • 1
  • 8