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

ggplotly with geom_bar shows wrong y-axis values when moving the cursor onto the bar

I have the following code creating a bar plot: require(data.table) require(plotly) require(ggplot2) df1 <- data.table(Time = seq(50, 290, 30), Enter = c(155000, 400000, 950000, 950000, 1000000, 1100000, 1100000, 1100000, 1150000), Exit = c(150000,…
sh_student
  • 369
  • 2
  • 14
2
votes
2 answers

Change the bar width does not work in geom_bar function

I am trying to change the bar width of my plots, my codes are here: ggplot(df_densityWindow, aes(x = idx, y = density, color = factor(location))) + geom_bar(stat = 'identity', fill = 'white', width = 1) + theme_bw() + facet_grid(marker ~ case,…
Haoyang Mi
  • 55
  • 5
2
votes
1 answer

Assign colours in geom_bar in different plots

I have a dataset with different species and year of their observation (in 3 categories). I would now like to make one plot per species with their observations per year and assign each year-category (each bar) a different color, but it should be the…
2
votes
2 answers

How to make a barplot with two y-variables side by side and standar errors

I have a dataframe as shown below: df1<- data.frame(Hour=c(0,6,12,18,24,0,6,12,18,24), meanType=c("mean_A","mean_A","mean_A","mean_A","mean_A","mean_B","mean_B","mean_B","mean_B","mean_B"), …
Dekike
  • 1,264
  • 6
  • 17
2
votes
1 answer

label datapoints when using geom_jitter overlaying on a box plot

I'm overlaying data points on a box plot. The problem I'm encountering is when trying to label the data points, the labels are not displayed over the data point. Any help here is appreciated. Thanks df <- data.frame(sno= c(1:10), A =sample(1:1000,…
user1946217
  • 1,733
  • 6
  • 31
  • 40
2
votes
1 answer

Text aesthetic with paste0 function in ggplot2 alters geom_bar fill order; How to fix it?

I'm attempting to make a stacked bar chart mapping a variable to fill on a log10 scale. I'd like to pass it through ggplotly, in order to have data inspection possible via tooltip. There are two problems. First, when I log transform the scale of…
A.Pehr
  • 23
  • 6
2
votes
1 answer

R ggplot2 customize legend with multiple geom_bar in one dataframe

My question is close to this Legends for multiple fills in ggplot and yet not the same. Let me explain. I have a dataframe that looks like this: df <- data.frame( 'sf'=c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'), 'totalsf'=c(28, NA, NA, 32,…
nathkpa
  • 121
  • 8
2
votes
1 answer

How to make a stacked barchart in ggplot from a long dataframe format?

I have a long dataframe format which is created like this: testAppVectorJG <- c(17, 155, 200, 200, 382, 499, 548, 548, 642, 642, 699, 699) testVectorJG <- c(testAppVectorJG[1], diff(testAppVectorJG)) testAppVectorJW <- c(145, 209, 366, 548, 548,…
JNab
  • 135
  • 10
2
votes
1 answer

How to label geom_bar(position = 'fill') using geom_text()

after quite some time searching through SO, I did not find an example that solved my question: How to label geom_bar(position = 'fill') using geom_text()? mydf = data.frame( 'sample' = sample(x = LETTERS[1:3], size = 111,replace = T), 'category'…
bud.dugong
  • 689
  • 7
  • 16
2
votes
0 answers

ggplot geom_bar() and base barplot

I'd like to reproduce the following base barplot, using ggplot2::geom_bar(). Toy data : set.seed(314) dat <- data.frame("Player" = rep(c("P1", "P2", "P3", "P4", "P5"), times = 2), "Score" = runif(n = 10, 0, 10) * 3) base barplot :…
i94pxoe
  • 577
  • 3
  • 11
2
votes
1 answer

change to swedish charactors and related ggplot geom_bar issues in R

I have 2 issues related to Swedish characters. I am fetching data directly from MS SQL database. 1.could anyone gives me a hint how could i change the back to Swedish characters in R? I use write.csv write the data out to csv then copy and paste…
CloverCeline
  • 511
  • 3
  • 18
2
votes
2 answers

bar chart of row freq ggplot2

I have the following data: dataf <- read.table(text = "index,group,taxa1,taxa2,taxa3,total s1,g1,2,5,3,10 s2,g1,3,4,3,10 s3,g2,1,2,7,10 s4,g2,0,4,6,10", header = T, sep = ",") I'm…
2
votes
3 answers

Ordering Legend in Multi-Bar ggplot2 Chart

I would like to have a multi-bar chart, horizontal bars, where the legend for the bar-color is in the same order as the bars themselves. I've looked at several articles that have influenced the example here, but I can't make it work. In this…
2
votes
1 answer

Swimmer survival plot ggplot_Events color coded by time duration

One question regarding the time axis for Swimmer waterfall plot. I generated the swimmer plot using the code below> However, I would like to have the bars for each subject colored by the responseType (rather than "Stage") based on the…
rk123
  • 67
  • 1
  • 8
2
votes
2 answers

ggplot2 geom_bar: Centering bars

I would really appreciate help with a ggplot2 issue. I've been looking around it for long, so my best chance is now here. I provide a reproducible script. What I'd need to do is center the bars horizontally. For now, they polarise towards the…
Pablo Bernabeu
  • 402
  • 4
  • 23