Questions tagged [geom-text]

`geom_text` is the geometric object description for creating text-labels in a plot in `ggplot2`

geom_text is the geometric object description for creating text-labels in a plot in .

ggplot2 is an actively maintained open-source chart-drawing library for R.

540 questions
64
votes
2 answers

Is there a fix for jagged, poor-quality text produced by geom_text()?

While adding annotation text to a plot I noticed that geom_text() produced unsightly, jagged text, while annotate() produced smooth, nice-looking text. Does anyone know why this happens and if there's any way to fix it? I know I could just use…
eipi10
  • 91,525
  • 24
  • 209
  • 285
49
votes
2 answers

geom_text how to position the text on bar as I want?

I would like to adjust the text on the barplot. I tried to adjust hjust/vjust to display as I like it but it seems like it's not working properly. ggplot(data) + geom_bar(aes(name, count, fill = week), stat='identity', position =…
tmhs
  • 998
  • 2
  • 14
  • 27
41
votes
2 answers

How to jitter/remove overlap for geom_text labels

In the figure, is it possible to jitter the state abbreviation labels a bit so they don't overlap? If I use check_overlap = TRUE, then it removes some observations that overlap, and I don't want that. I also don't want the geom_label_repel, since…
37
votes
1 answer

How to add frequency count labels to the bars in a bar graph using ggplot2?

I want to plot frequency distribution of an [r] factor variable as a bargraph, where bars represent the frequency counts of the factor levels. I use ggplot2 to do that and there's no problem with that. What I can't figure out is how to add frequency…
Tamer Koksal
  • 393
  • 1
  • 3
  • 5
35
votes
1 answer

Position geom_text in the middle of each bar segment in a geom_col stacked barchart

I would like to position the corresponding value labels in a geom_col stacked barchart in the middle of each bar segment. However, my naive attempt fails. library(ggplot2) # Version: ggplot2 2.2 dta <- data.frame(group = c("A","A","A", …
chamaoskurumi
  • 2,271
  • 2
  • 23
  • 30
28
votes
1 answer

How to change font color in geom_text in ggplot2 in R?

I am generating some basic bar plots in ggplot2 using geom_bar. I would like the number to be listed in the same color above each bar and I am using geom_text. I am filling the bars by using scale_fill_manual(values = alpha(c("#000000",…
Jess
  • 283
  • 1
  • 3
  • 6
21
votes
2 answers

ggplot2: geom_text resize with the plot and force/fit text within geom_bar

This is actually two questions in one (not sure if goes against SO rules, but anyway). First question is how can I force a geom_text to fit within a geom_bar? (dynamically according to the values plotted) Looking around, the solutions I found were…
elikesprogramming
  • 2,506
  • 2
  • 19
  • 37
20
votes
5 answers

Specify position of geom_text by keywords like "top", "bottom", "left", "right", "center"

I wish to position text in a ggplot without specifying x and y positions, but instead using keywords, like e.g. in graphics::legend ("The location may also be specified by setting x to a single keyword from the list "bottomright", "bottom",…
CCurtis
  • 1,770
  • 3
  • 15
  • 25
20
votes
1 answer

Left-justify geom_text layer with ggplot2

ggplot2 automatically centers the text in a geom_text layer. For example: library(ggplot2) library(tidyverse) df <- data_frame(text = c("A short sentence.", "A slightly longer sentence.", "This sentence is…
David Ranzolin
  • 913
  • 1
  • 6
  • 18
16
votes
2 answers

Change geom_text's default "a" legend to label string itself

Similarly to this question, I want to change the default "a" in the legend, but rather than removing it completely, I want to replace it with the labels themselves. That is, the first line of the legend should have a colored icon labeled "se" with…
half-pass
  • 1,851
  • 4
  • 22
  • 33
15
votes
1 answer

Put labels over negative and positive geom_bar

I'd like to visualize a data using bar chart and ggplot. I have the data below, when I want to vis this data the text for negative values are not showing below the Bar . dat <- read.table(text = "sample Types Value sample1 A -36 sample2 B …
Tamra.y
  • 235
  • 3
  • 9
12
votes
2 answers

Consistent positioning of text relative to plot area when using different data sets

I generate several plots where data may have different x and y ranges. I wish to place a text annotation in all plots, at exactly the same position relative to the plot area. Example of the first plot, where I add text with annotate and position it…
Nautica
  • 2,004
  • 1
  • 12
  • 35
10
votes
3 answers

Change geom_text to bold when parse=TRUE

I am annotating faceted plots to include a superscript, yet am having trouble making the text bold. I realise that this has something to do with creating an expression outside the plot call and then specifying parse=TRUE. There is probably quite a…
J.Con
  • 4,101
  • 4
  • 36
  • 64
10
votes
1 answer

Alternate geom_text position with hjust

I'm plotting a stacked bar graph and use geom_text to insert the value of each stack. The difficulty I'm facing is that some stacks are very small/narrow, so that the text of two stacks overlap each other and hence is not very readable. I would like…
talat
  • 68,970
  • 21
  • 126
  • 157
9
votes
2 answers

Why is geom_text() plotting the text several times?

Please consider the following minimal example: library(ggplot2) library(ggrepel) ggplot(mtcars) + aes(x = mpg, y = qsec) + geom_line() + geom_text(x = 20, y = 20, label = "(20,20)") I guess you can see pretty easily that the text "(20,20)"…
swolf
  • 1,020
  • 7
  • 20
1
2 3
35 36