Questions tagged [geom-col]

Part of the `ggplot2` library for R, `geom_col` is a chart type using columns to represent data.

169 questions
7
votes
1 answer

Shift x-axis ticks with scale_x_datetime and geom_col so bars are NOT centered on tick mark

I am plotting time series data in half-hour intervals, using geom_col() to show number of birds counted in each interval. ggplot2 plots each bar centered over the x-axis tick mark, but I need each bar to begin to the right of each tick mark. In…
m.hand
  • 105
  • 3
5
votes
1 answer

How to label only the modal peak in a geom_col plot

I'd like to put a label above only the modal bar (the tallest peak) on my geom_col plot, giving the x-axis value (CAG). Here's an example, but I can only get it to label every peak. x <- seq(-20, 20, by = .1) y <- dnorm(x, mean = 5.0, sd = 1.0) z <-…
Mike
  • 921
  • 7
  • 26
5
votes
1 answer

How to plot one factor level as a base on geom_col/geom_area

I've written following function that makes a customised stacked plot: stacked_plot <- function(data, what, by = NULL, date_col = date, date_unit = NULL, type = 'area'){ by <- enquo(by) what <- ensym(what) date_col <- ensym(date_col) …
Kuba_
  • 886
  • 6
  • 22
5
votes
2 answers

Changing the order of the groups in ggplot in R

I am using ggplot to draw a bar chart. How can I change the order of the groups in the bars? In the following example, I want to have type=1984 as the first stack of the bars, then type=1985 on top of 1984 and so on. series <- data.frame( time =…
Hossein
  • 461
  • 3
  • 9
  • 17
4
votes
2 answers

Change ggplot bar chart fill colors

With this data: df <- data.frame(value =c(20, 50, 90), group = c(1, 2,3)) I can get a bar chart: df %>% ggplot(aes(x = group, y = value, fill = value)) + geom_col() + coord_flip()+ scale_fill_viridis_c(option = "C") + …
Zhiqiang Wang
  • 6,206
  • 2
  • 13
  • 27
4
votes
1 answer

How to remove ggplot2 background and crop margins around geom_col

I want to make a "timeline" using a stacked column chart. What I want to do is to remove all background so I just have a bar and nothing else. I am stuck with the white background of the chart. Here is a minimal example: mytheme <- theme( …
Kaveh1000
  • 153
  • 1
  • 11
3
votes
1 answer

Can I add grouping line labels above my ggplot bar/column chart?

I'm interested in adding grouping labels above my ggplot bar charts. This feature exists for data visualizations such as phylogenetic trees (in ggtree), but I haven't found a way to do it in ggplot. I've tried toying around with geom_text, and…
3
votes
1 answer

What are all the positions for geom_bar() and geom_col()?

I've looked in an infinity of places, but none of them actually put all the positions available for these two geoms. I know there are stack (to put one on top of the other), dodge (to make little clusters with each group side-by-side), identity (to…
Érico Patto
  • 1,015
  • 4
  • 18
3
votes
1 answer

geom_col with facet_grid with margins=TRUE not stacking up?

The bars in the margins appear to be picking the maximum facet rather than summing them up as I expected. Shouldn't they be stacking up in the margins? Is this a bug? Any suggestions how I might change geom_col / geom_bar / position settings, or a…
Arthur Yip
  • 5,810
  • 2
  • 31
  • 50
3
votes
1 answer

R - change shape legend in ggplot2 (geom_col)

I am trying to change the shape of the legends for a geom_col plot. By default, the legend is square, and I would like to change to round (or triangle or anything else). Since the colors are controlled by fill, I would assume overwriting this…
Qin
  • 173
  • 8
3
votes
3 answers

How to plot two variables side by side in the same ggplot using geom_col?

I have the following data structure(list(id = 1:7, date = c(2019L, 2019L, 2019L, 2019L, 2019L, 2019L, 2019L), station = structure(1:7, .Label = c("41B004", "41B011", "41MEU1", "41N043", "41R001", "41R012", "41WOL1"), class = "factor"), days =…
Alessandro
  • 129
  • 1
  • 8
3
votes
1 answer

r add background color to geom_label()

I have a function for creating a bar chart that looks like this: my_bar_chart <- function(data, column, title, change_order=FALSE){ out <- data %>% group_by({{column}}) %>% summarize(count = n()) %>% mutate(percent =…
b-ryce
  • 5,752
  • 7
  • 49
  • 79
3
votes
1 answer

geom_col values out of order

I am new to R. I am having trouble with the ordering of the geom_text elements in the below geom_col chart. I believe it has something to do with the position = position_dodge2(preserve = "single") line, but I am not sure. Sample code and outputs…
2
votes
2 answers

Get row columns by group for geom_col in ggplot

I am trying to calculate row percentages by demographics of various score levels--in my data, that would be what % of white people (or % of black people, or % male, or % who have education level 2, and so on) have a score of 0 (or 1, 2, or 3)--and…
a_todd12
  • 449
  • 2
  • 12
2
votes
1 answer

how to add lines over a column bar graph where the lines pass by the middle-top of the bars considering bars with position='dodge'?

Here I provide an example of what I have tried: df <- data.frame(a = rep(c(1:12), each = 2), b = c("yes", "no"), c = sample(x = 1:200, size = 24)) ggplot(df, aes(x = a, y = c)) + geom_col(aes(fill = b), position…
Miguel_s
  • 79
  • 3
1
2 3
11 12