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

geom_bar not showing every values

I want to draw a bar plot, with ggplot and geom_bar, but it seems that the behavior of geom_bar is not consistent. I don't understand why. My data is a time series of…
popo
  • 131
  • 1
  • 6
3
votes
1 answer

With ggplot2, what code creates bars made of individual words and their count?

To convey the relative frequencies of key words, I would like each "bar" in a plot to consist of one of the words repeated vertically by its frequency. The ggplot code below removes the outline of the bar and the fill, but how can I create a…
lawyeR
  • 7,488
  • 5
  • 33
  • 63
3
votes
1 answer

How to add custom labels from a dataset on top of bars using ggplot/geom_bar in R?

I have the attached datasets and use this R code to plot the data: plotData <- read.csv("plotdata.csv") ix <- 1:nrow(plotData) long <- melt(transform(plotData, id = ix), id = "id") # add id col; melt to long form ggp2 <- ggplot(long, aes(id, value,…
Rlearner
  • 351
  • 1
  • 4
  • 13
3
votes
2 answers

Different space between bars geom_bar

I tried my best to read related questions to my issue. The most relevant was: question. However I was not able to figure out how to solve my issue. I had a dataset like structure(list(COMPANY = structure(1:5, .Label = c("Architecten", " 2.0", "…
2
votes
0 answers

Removing NAs changes bar width in ggplot with facet_grid

I am plotting the answers in a bar chart, which looks good when I use the whole dataset, including the NAs: anm$Q42<-factor(anm$Q42,levels=c('once_per_week','once_per_month', …
2
votes
4 answers

How to make different patterns and colors in different category of data using ggplot in R?

I would like to make my data have different colors for species and different patterns for sex. However, I can only set to make it different colors according to the sex. Here is my data, data This is how I run my script, #making bar…
Woony
  • 33
  • 4
2
votes
3 answers

Show individual bar count label in grouped bar plot

I am trying to plot Male and Female in different Age Groups. I am trying to show the individual Male and Female Count in their respective bars/colours but the graphs shows the total count value in the AgeGroup. How I am going to show/label the…
Usman YousafZai
  • 1,088
  • 4
  • 18
  • 44
2
votes
4 answers

order y axis by count of one particular value in column with geom_bar

wondering how I can order the clusters on y-axis by decreasing count of kiwi? df = data.frame() df = data.frame(matrix(df, nrow=200, ncol=2)) colnames(df) <- c("cluster", "name") df$cluster <- sample(20, size = nrow(df), replace = TRUE) df$fruit <-…
MeganCole
  • 39
  • 1
  • 6
2
votes
2 answers

Add brackets over a bar plot of factor variable (geom_bar, geom_bracket)

I am trying to use geom_bracket to annotate a bar plot of ordered categorical bars. Example data and plot: df <- tibble( country= c("ENG","ESP", "ITA", "FRA", "NLD", "POR", "AUT", "TUR", "CHE", "RUS"), share=c(25.71, 21.74, 11.54, 10.49, 3.76, …
2
votes
2 answers

How to draw secondary axis of a bar chart in R?

I have the following data.frame and R-code and i am trying to produce a bar graph where precipation on the secondary axis should be reversed. library(tidyverse) DF <- data.frame(Month = 1:12, Flow = c(1,2,5,30,45,50,40,25,15,10,4,1.2), …
Hydro
  • 1,057
  • 12
  • 25
2
votes
2 answers

How to remove select labels in ggplot geom_bar plot and center these labels?

Is it possible to remove certain/specific labels from geom_bar ggplot (geom_text) for repeated values and center this value on the plot/bars? My data: structure(list(prey_name = c("Amphipod", "Byths", "Chiro.Adult", "Chiro.Larvae", "Chiro.Pupae",…
FishyFishies
  • 301
  • 3
  • 14
2
votes
1 answer

How to color specific values from a variable to show them (as a bar graph and table) in Shiny?

I'm trying to create a shiny app where I can select as many countries as I want with two objectives. a) Create a graph (as shown below) where all countries that I select, are colored. b) Create a table where I can see the selected countries and…
2
votes
0 answers

Add counts to stacked bar plot with data from 2 data frames

There are several posts similar to this, but I haven't been able to find the right solution for what is probably a simple problem. I am trying to produce a stacked bar plot with counts for both stacks, but the data is in two data frames. This may…
Doda
  • 285
  • 1
  • 9
2
votes
1 answer

Manually adjusting colors in ggplot (geom_bar)

I want to (manually) chance the color of my bar plot. Right now, I used fill=group to determine the color scheme. However, I don't like the bright pink color and want to change this manually in a purple color, the rest of the colors are fine. How…
Pepijn95
  • 321
  • 1
  • 6
2
votes
2 answers

Change font color of one stacked bar

How do I change the font color for only the top stacked bar?
Shannon
  • 125
  • 7