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

Displaying compact letters over box plot when using geom_text and facet_grid

This is my first question, so I am sorry if I haven't made the problem/example clear! I am trying to use ggplot2 to make a boxplot with compact letters displayed over each boxplot. I can achieve this when the plot is not faceted, however, when I…
kaastengel
  • 21
  • 3
2
votes
1 answer

Strategies in mapping text size to data in ggplot

I would like to consult on how to map text size to data in ggplot(). In the following silly example, I have data describing some English letters and the average score of "liking" each letter received. That is, imagine that we surveyed people and…
Emman
  • 3,695
  • 2
  • 20
  • 44
2
votes
1 answer

How to have the geom_text left-aligned with ggplot2

I want to left-justify geom_text layer with ggplot2. I am using the following code library(tidyverse) library(hydroGOF) library(scales) summ <- df %>% group_by(Date) %>% summarise(R = cor(x, y, use="pairwise.complete.obs"), MBE =…
UseR10085
  • 7,120
  • 3
  • 24
  • 54
2
votes
1 answer

addint text labels to a grouped barchart in R

my data looks something like this: structure(list(region1 = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L), .Label = c("Location1", "Location2", "Location3",…
Nneka
  • 1,764
  • 2
  • 15
  • 39
2
votes
1 answer

Reduce line-height in R ggplot in geom_label() and geom_text(), when line-breaking with \n

The following code creates the following graph: data.frame(x = c(1,2,3,4), y = c(1,2,3,4)) %>% ggplot() + geom_point(aes(x = x, y = y)) + geom_label(aes(x = 2.5, y = 2.5, label = 'label here \n with break'), fill = '#dddddd') We need to…
Canovice
  • 9,012
  • 22
  • 93
  • 211
2
votes
1 answer

Adding multiple text labels to a single facet_grid panel

Following this example I am able to add some text to each facet grid but on one panel I need 2 separate labels over each group of boxplots, similar to the spacing the labels produced by stat_compare_means. My current logic can only accommodate one…
skiventist
  • 425
  • 4
  • 11
2
votes
2 answers

R: Display character or categories on a stack bar

I am trying to add the category and percent to each level in a stack bar, example: Category <- c(rep(c("A", "B", "C", "D"), times = 4)) Data <- data.frame( Category) p= ggplot(Data,aes(x=factor(""),fill=factor(Category)))+ …
2
votes
1 answer

sf to data.frame: why as_Spatial needed before as.data.frame

Let's say I want to add labels to a geom_sf() plot, to get the following: as of Nov/2020 the method does not exist, thus I get a warning and nothing gets plotted when I try: library(sf) nc <- st_read(system.file("shape/nc.shp",…
Dan
  • 1,711
  • 2
  • 24
  • 39
2
votes
1 answer

ggplot2 labels won't dodge with geom_col bars

I've been through related questions and those answers aren't solving my problem of labels not dodging to match the geom_col bars: Data x <- structure( list(capacity = c(0, 0, 0, 2.1, 3.1, 4, 4.6, 5.6, 6, 1.9, 2.3,…
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
2
votes
3 answers

R how to place text on ggplot relative to axis

I am attempting to use geom_text() in ggplot to place sample sizes on a bar chart with defined limits determined by ggplot. For most of my plots, I have been able to get away with specifying the y-value for text placement as 0. However, for a few…
Eric Dilley
  • 337
  • 2
  • 10
2
votes
2 answers

Cannot get geom_text labels with facet_wrap to work

I can't seem to figure out why this code isn't working for me. I am trying to add different geom_text labels to each facet of this graph. I've created a df for the annotation information. Here is a sample of my dataset and code: testParv <-…
JuliaB
  • 23
  • 2
2
votes
1 answer

Bars disappear when I add geom_text() to show label on the bars in ggplot2

This is my code and when I add the last line of code, which is geom_text() to add labels on the bars, my bars disappears. Moreover, this happens in geom_bar(position="fill") but not in geom_bar(position="stack"). Couldn't find out the reason. My…
Ravi Pande
  • 49
  • 7
2
votes
1 answer

How to evenly plot geom_text in R?

I am trying to create an infographic style plot in ggplot but am having a lot of trouble figuring out how to start. I want to plot counts of a variable (women) inside of an image, with the name of the country underneath. I figured this would need to…
Grace
  • 55
  • 5
2
votes
2 answers

Ggplot2: geom_text() adds additional, unwanted values to plot

I have a seemingly simple problem that I can't solve: too many values appear on my plot. I only want to see the total count (tot_q which is n) once, and the relevant pc (percentage for categories where quality is 1). Here is my example…
Mari
  • 53
  • 7
2
votes
1 answer

Changing of color for geom_text gives completely different color then called for

I want to add labels to my ggplot2 bars and change the color of the label. Somehow I can't. My dataset is (simplified) approximatly in this format: data$value <- runif(27, min=10, max=60) data$A <- factor((rep(1:3, each=9))) data$B <-…