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
9
votes
2 answers

Add percentage labels to a stacked barplot

I have successfully made a stacked barplot in R where the percentages add up to 100% for several different categories. I made an example dataframe here. example.Category<- c("Cat1","Cat2","Cat3","Cat4","Cat5","Cat6") percent.good <-…
David
  • 259
  • 1
  • 2
  • 8
8
votes
4 answers

ggplot2: How to conditionally change geom_text's vjust when low bars make text exceed bar's bottom

When plotting a bar chart, I often add labels to bars to signify the y-value for each bar. However, I run into trouble when the bar becomes too low, making the label unreadable or simply ugly. Example library(ggplot2) df_blood <-…
Emman
  • 3,695
  • 2
  • 20
  • 44
8
votes
3 answers

annotate boxplot in ggplot2

I've created a side-by-side boxplot using ggplot2. p <- ggplot(mtcars, aes(x=factor(cyl), y=mpg)) p + geom_boxplot(aes(fill=factor(cyl))) I want to annotate with min, max, 1st quartile, median and 3rd quartile in the plot. I know geom_text() can do…
Paul
  • 127
  • 1
  • 2
  • 8
7
votes
1 answer

R - nudge only selected values and keep others static with geom_text_repel

I want to use geom_text_repel to have my labels lie as close to the edge of a pie graph as possible unless the percent is under a certain value, in which case the label should be nudged further away and connected with a line. I adapted a solution…
Nicholas Hassan
  • 949
  • 2
  • 10
  • 27
7
votes
2 answers

How to change colour and position of geom_text for just one bar in a barplot in ggplot2 (R)?

I'm trying to create a bar plot with the depicted values written inside the bars using ggplot2. I still want to label the group with value "0" but in a different colour (black) and just above the x-axis. How can I change the position and colour of…
R.Van
  • 117
  • 3
  • 7
7
votes
2 answers

How do I add percentage and fractions to ggplot geom_text label?

I have a dataset where I am interested in looking at a score on a test and the percentage of people experiencing an event: dat <- data.frame(score = 1:7, n.event = c(263,5177,3599,21399,16228,10345,1452), n.total =…
Jacob Curtis
  • 788
  • 1
  • 8
  • 22
7
votes
2 answers

R: ggplot stacked bar chart with counts on y axis but percentage as label

I'm looking for a way to label a stacked bar chart with percentages while the y-axis shows the original count (using ggplot). Here is a MWE for the plot without labels: library(ggplot2) df <- as.data.frame(matrix(nrow = 7, ncol= 3, …
Johanna
  • 323
  • 1
  • 3
  • 10
7
votes
1 answer

adding geom_text from different dataset to geom_bar

I have a bar plot with a facet grid, and I would like to add the number of observations per sub-plot which are stored in a separate dataframe. The bar plot is produced with bar.plot <- ggplot(BarDiff.m.s, aes(x=value.change, fill=incompatibility))+ …
zoowalk
  • 2,018
  • 20
  • 33
6
votes
2 answers

How to use stat="count" to label a bar chart with counts or percentages in ggplot2?

I'm trying to produce a stacked column chart with data labels. I'm able to produce the chart, but was unable to find a way to input data labels. I have tried geom_text() but it keeps asking me to input a y label (which if you see the ggplot code is…
nike.96
  • 67
  • 1
  • 1
  • 5
6
votes
2 answers

How do I add a comma separator to a text label in geom_text?

I need to change the number format in geom_text() to include a comma. I have seen the related questions and I can't get those solutions to work. I've tried the "sep =" one, the count/sum(count) kind, and some other code I just transcribed without…
Jon Robinson
  • 65
  • 1
  • 4
6
votes
0 answers

R ggplot, geom_text to round labels within the label command?

Right now I can get labels of the fill value above by bars in ggplot geom_bar. But what I can't seem to do is change the number of decimal places of the label. Right now it has 9 decimal places and I only want 2. I have tried using round() and…
Natalie
  • 91
  • 1
  • 1
  • 7
6
votes
1 answer

Avoid overlapping geom_point and geom_text in ggplot2

How can I avoid that these 2 layers in ggplot2 overlap? I try to display the text so that they are not laying above the points. check_overlap does a great job with avoiding that the text overlaps itself, but not with other layers. I also tried the…
Max
  • 61
  • 1
  • 2
5
votes
2 answers

Overlapping labels with geom_dl()

My line plot is suitable except my labels overlap too much. I realize their respective datapoints are close, but is there a way to pretty up the label spacing? My data and code: library(ggplot2) library(directlabels) #geom_dl #Original df df <-…
RKeithL
  • 157
  • 1
  • 9
5
votes
3 answers

Remove segment around label/text in ggplot2

Consider a plot with a segment/line and a text/label. I'd like the text to overlay the segment such that the text does not overlap the segment. I tried using geom_label but I still want the background to be the same, just the other objects to be…
Maël
  • 45,206
  • 3
  • 29
  • 67
5
votes
3 answers

Forest plot with table ggplot coding

I am trying to get a table side by side with my forest plot but I am having a lot of trouble doing so. I am able to make a forest plot with the following…
davidk
  • 133
  • 2
  • 11
1
2
3
35 36