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

How to get rid of wider bars of a ggplot2 plot with geom_bar() in cases of count=0

Here is my data.frame(): df <- data.frame(Round = rep(c("A", "B", "C" ),150), Group = rep(c("UP", "DOWN"),75),Task = rep(c("T1", "T2", "T3", "T4", "T5"),30), V2 = sample(c(0,1,2), 50, replace = T), V1 = sample(c(0,1,2), 50, replace = T)) dfmelt <-…
3
votes
0 answers

How to set the origin of y-axis in geom_bar (ylim does not work)

I am trying to control the range of the y-axis in a bar plot using ggplot. For this graph, I would like to the set the y-axis origin at 1, and not at 0 as ggplot2 does by default. For this example, lets assume I want to plot the median value for a…
FabF
  • 61
  • 5
3
votes
1 answer

ggplot geom_bar() customize by linetype and fill

I am using ggplot2 and geom_bar() to plot some statistics. Is there a way to customize the fillings in the bar, and the line type for each of the bars? I would like to highlight two key features: There are five bars overall and the numbers they…
rajvijay
  • 1,641
  • 4
  • 23
  • 28
3
votes
1 answer

How to create custom color palette to be used by scale_fill_manual()

Consider the following code that makes a bar chart with a purple color palette library(dplyr) library(ggplot2) dd <- mpg %>% group_by(manufacturer, cyl) %>% summarise(n = n()) %>% ungroup() mm <- dd %>% …
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
3
votes
1 answer

Overlapping bars when trying to fix bar width using facet_wrap from ggplot2

I have the same problem which is explained here Bars in geom_bar have unwanted different widths when using facet_wrap That is, when facetting my bars show a different width. I have tried the solution proposed there, but it seems I'm doing something…
Pablo
  • 79
  • 9
3
votes
1 answer

Axis labels and title clipped in barplot clipped with plotly in Rshiny

I am having certain issues while converting ggplot2 plots to plotly plots. Here is my code: > dput(dat.c) structure(list(Cell_Line = structure(1:15, .Label = c("NBLS", "NBSD", "NGP", "NLF", "RPE1", "RPE1MYCN40HT", "RPE1MYCNWT", "RPE1WT40HT",…
Komal Rathi
  • 4,164
  • 13
  • 60
  • 98
3
votes
2 answers

ggplot2: create ordered group bar plot - (use reorder)

I want to create grouped bar plot while keeping order. If it was single column and not a grouped bar plot use of reorder function is obvious. But not sure how to use it on a melted data.frame. Here is the detail explanation with code example: Lets…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
3
votes
2 answers

ggplot labels on bargraph position

I am REALLY sorry if this is a repeated question. But for some reason the answeres previously given did not work for me. I have the following df: Country<-c("Chile", "Chile",…
samyandi
  • 141
  • 4
  • 9
3
votes
1 answer

ggplot: panel of bar charts

I have the following data set: Year, Height, Width, Weight 1990, 5, 45, 190 2000, 7, 77, 210 2010, 2, 20, 150 I would like to plot a single column of bar charts with a plot for height, width, and weight. In each bar chart, the values would be…
Dan
  • 11,370
  • 4
  • 43
  • 68
3
votes
1 answer

How can I indicate groups (such as chromosomes) on a continuous axis using ggplot2?

This is what I want to plot: Using ggplot2, I can plot the correct bars, but with the locus number stated on the x-axis instead of the chromosome number. It just plots the number of each bar, like 1,2,...,500, but it doesn't show the chromosome.…
Ziv
  • 63
  • 1
  • 4
3
votes
1 answer

Showing geom_abline in legend without bar

I want to show the added line via geom_abline in the legend since the bar chart is denoted in the x axis labels. How embarrassing, not sure how i forgot toy data. I also cleaned up the example making sure i was running the most up to date version…
Josh R.
  • 449
  • 2
  • 4
  • 13
3
votes
0 answers

R ggplot stacked bar label spacing

I am working on a stacked bar chart that illustrates cumulative percentages. I would like to show the percentage values on the bars, though need them to be spaced such that they don't overlap, but are still intuitively associated with their…
Alex
  • 971
  • 4
  • 15
  • 28
3
votes
1 answer

Add points to grouped bar plot (ggplot2)

I have a dataset containing measurements at two timepoints. I have made a barplot of the data of the first timepoint, and would like to add points for the second timepoint (this is just meant as a reference). As you can see below the points are…
mats
  • 133
  • 1
  • 3
  • 10
3
votes
1 answer

Control the fill order and groups for a ggplot2 geom_bar

library(ggplot2) data <- data.frame( group=factor(c("a","c","b","b","c","a")), x=c("A","B","C", "D","E","F"), y=c(3,2,10,11,4,5)) > data group x y 1 a A 3 2 c B 2 3 b C 10 4 b D 11 5 c E 4 6 a F …
user3375672
  • 3,728
  • 9
  • 41
  • 70
3
votes
1 answer

Grouped bar graph custom colours

I have the following data and wish to create a grouped bar graph like so: data<-as.data.frame(c("a","b","c","a","b","c")) colnames(data)<-"Y" data$X<-c("x","x","x","y","y","y") data$Z<-c(1,2,3,1,2,3) ggplot(data, aes(x=X, y=Z, fill=Y) + …
user2568648
  • 3,001
  • 8
  • 35
  • 52