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
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

R Animating line plot using gganimate and geom_text

I made animated plot using gganimate, so I can see the change in y axis as the year goes by. So far, I have the setting below and it does most of the stuff I'm trying to achieve. However, I definitely want to clean up the geom_text portion a little…
3
votes
2 answers

labeling geom_point in ggplot R

I am trying to recreate a plot and I have several lines in there, which are in the legend but next to this the plot also has some points. How could I put labels in this plot at the points. Note that the points are not in the data frame. My code…
Elliot
  • 55
  • 1
  • 5
3
votes
2 answers

How to pass an expression to a geom_text label in ggplot? (Continued)

This is a follow-up my original question for how to pass an expression with subscript to a geom_text label in ggplot. Duck provided a great solution using parse = T within the geom_text() command. However, I am now running into a problem because the…
Reb Gray
  • 87
  • 1
  • 4
3
votes
2 answers

Bounding position for geom_text()

I am making several instances of a tilted bar chart. As the sizes of count and the differences in percent vary, part of one of the labels (count) is pushed outside the bar in some instances. I need the labels to be entirely inside the bar in all…
rjen
  • 1,938
  • 1
  • 7
  • 19
3
votes
0 answers

How to add annotation to the top of ggplot using for-loops

I have 10 ggplot graphs that were created using for-loops. I would like to annotate the graphs, but the Y position changes for each graph (x position remains the same). Y axis on graph 1 runs from 2-8 Y axis on graph 2 runs from 800-1400 etc. My…
3
votes
2 answers

ggplot2::geom_text(): how to display all factor levels, but suppress specific values like '0':

Here is code to give context to my question: set.seed(1); tibble(x=factor(sample(LETTERS[1:7],7,replace = T),levels = LETTERS[1:7])) %>% group_by_all() %>% count(x,.drop = F) %>% ggplot(mapping = aes(x=x,y=n))+geom_bar(stat="identity")+geom_text( …
HumanityFirst
  • 305
  • 1
  • 8
3
votes
2 answers

Add text labels at the top of density plots to label the different groups

I have the following ggplot density plot ggplot(mpg, aes(cty)) + geom_density(aes(fill=factor(cyl))) How do I remove the legend , and add labels above each distribution to denoted the group it belongs to?
Tony
  • 33
  • 3
3
votes
1 answer

geom_text in ggplot with geom_col and position "dodge"

I have issues with my labelling. I have read the other posts on the topic, but can't figure out what is wrong. Can you please help? Data: df <- structure(list(type = c("Activity (ACTIV)", "Activity (ACTIV)", "Activity (ACTIV)", "Function (MEREC)",…
william3031
  • 1,653
  • 1
  • 18
  • 39
3
votes
1 answer

Display data values on geom_line

I have created a plot using ggplot and geom_line and would like to have the individual data values (numbers) displayed on the plot. This is my code so far: ggplot(errors_prob_3) + geom_point(aes(x = ID, y = train_mean, colour = 'red'))…
MY.BK
  • 167
  • 1
  • 2
  • 12
3
votes
1 answer

Error in FUN(X[[i]], ...) : object not found when adding geom_text with facet

Adding geom_text(data = dat_text, mapping = aes(x , y , label = label)) line gives me the following error: Error in FUN(X[[i]], ...) : object 'sex' not found. This is so irrelevant that I have no idea what to do with it. Without the last line,…
parpar
  • 47
  • 1
  • 5
3
votes
1 answer

geom_text / geom_label with the bquote function

My data : dat <- data_frame(x = c(1,2,3,4,5,6), y = c(2,2,2,6,2,2)) I wish to display this expression beside the point (x=4,y=6) : expression <- bquote(paste(frac(a[z], b[z]), " = ", .(dat[which.max(dat$y),"y"] %>% as.numeric()))) But, when I am…
Loulou
  • 703
  • 5
  • 17
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…
3
votes
3 answers

ggplot2 putting data labels (geom_text) in wrong order

I'm having an issue with data labels incorrectly ordering using ggplot2. Unfortunately, other SE Q&As on this topic are not very insightful(example), so I'm having to reach out with a reprex. I have the following data: df =…
Thirst for Knowledge
  • 1,606
  • 2
  • 26
  • 43
3
votes
2 answers

R ggplot labels on stacked bar chart

I have data that I need to put into a stack bar chart but when I add the labels of the counts some of the labels are above the category and some are under the category. I tried modifying position arguments of the geom_text function to no…
user3357059
  • 1,122
  • 1
  • 15
  • 30