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

Change color of text based on threshold

I have some data which I want to use to make a heatmap. library(tidyverse) library(viridisLite) f<-tibble::tribble( ~wday, ~hour, ~WR, "Saturday", "9", 54.7272727272727, "Saturday", "10", 69.125, …
Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73
3
votes
1 answer

Center alignment of text over each bar on faceted, dodged bar plot using ggplot2 in R

I would like my text to be center-aligned above each bar in a faceted dodged bar plot. # setup library(ggplot2); library(tidyverse) data("iris") # graph iris %>% group_by(Species) %>% mutate(Petal_Group = ifelse(Petal.Width < median(Petal.Width),…
LC-datascientist
  • 1,960
  • 1
  • 18
  • 32
3
votes
1 answer

Labelling and theme of ggalluvial plot in R

For the past hours I have tried to understand the whole design/theme/labelling concept around ggalluvial, but I failed. Within minutes I was able to produce the kind of graph I want (thanks to the package ggalluvial), but I can't figure how to…
3
votes
0 answers

Text labels on condition for lollipop plot in ggplot

I'm putting together a lollipop plot that has a condition set on Var1 being greater than 1, where all the FALSE going to the left and are color coded in pink and all the TRUE go to the right of 1 and are color coded in blue. I'd like to add labels…
3
votes
2 answers

Adding significance levels in faceted plots with two results in the same x axis

I know that there are many questions already open to add significance level in ggplot2 in faceted plots. However, as a R beginner, I did not found a solution for my plot. My data (.txt file) is available in this…
Tiago Lima
  • 31
  • 4
3
votes
0 answers

ggplot facets: show annotated text in selected facets

I want to create a 2 by 2 faceted plot with a vertical line shared by the four facets. However, because the facets on top have the same date information as the facets at the bottom, I only want to have the vline annotated twice: in this case in the…
KoenV
  • 4,113
  • 2
  • 23
  • 38
3
votes
1 answer

R: place geom_text() relative to plot borders rather than fixed position on the plot

I am creating a number of plots using ggplot2 in R and want a way to standardize implementation of a cutoff line. I have data on a number of different measures for four cities over a ~10 year time period. I've plotted them as line graphs with each…
cparmstrong
  • 799
  • 6
  • 23
3
votes
1 answer

ggplot2 in R: annotate outside of plot and underline text

I've been scratching my head for hours on this. What I have up to now: library(ggplot2) library(grid) all_data = data.frame(country=rep(c("A","B","C","D"),times=1,each=20), value=rep(c(10,20,30,40),times=1,each=20), …
Nikowhy
  • 141
  • 2
  • 10
3
votes
1 answer

R ggplot annotation alignment

I am trying to create an annotation and align it. If I use: annotate("text", label = "atext", x = 1, y = 1) the center of the text (the e) gets positioned at (1, 1). However, I'd like the left border of the text (the a) to be at (1, 1). How do I…
3
votes
2 answers

geom_text(), plotmath, and %

I want to add "R^2 = 70%" to my plot using geom_text() (where ^ indicates a superscript). Without the % sign, it's easy: my.data <- data.frame(x=1:5, y=1:5) p1 <- ggplot(my.data, aes(x=x, y=y)) + geom_point() p1 <- p1 + geom_text(x=2.5,…
user13424
  • 111
  • 1
  • 4
3
votes
2 answers

ggplot labels on bargraph position

I am REALLY sorry if this is a repeated question. But for some reason the answeres previously given did not work for me. I have the following df: Country<-c("Chile", "Chile",…
samyandi
  • 141
  • 4
  • 9
3
votes
1 answer

Adjust the position of labels of vertical lines in ggplot?

I filtered diamond data frame based on the price varible to get prices lower than or equal 10000 and I named the new dataframe df. Then, I added a new column quantile that have the quantiles of price column. The highest price is in the 1st quantile…
shiny
  • 3,380
  • 9
  • 42
  • 79
3
votes
2 answers

r ggplot show cluster labels on the plot

I am new to R and I am trying to generate a series of figures for my clustering algorithm. Right now I am using the following code: ggplot(df,aes(x=V1,y=V2)) + geom_point(aes(colour = factor(cluster)),alpha=0.7)…
ahajib
  • 12,838
  • 29
  • 79
  • 120
3
votes
1 answer

Add less than symbol, "<", to a ggplot via geom_text in R

The short version: How would I make this contrived code plot a proper greek beta character AND the rest of the label string, with the space and the less than character and the numbers formatted as…
mightypile
  • 7,589
  • 3
  • 37
  • 42
3
votes
1 answer

Matching geom_text color to elements in plot and removing legend title in ggplot2

I have two questions: - how to have the same color in geom_text as in the geom_point? - how to remove legend title? Assuming the following data set: library(ggplot2) library(reshape2) speed <- c(0, seq(from = 30, to = 330, by = 60)) power1 <-…
AndriusZ
  • 822
  • 1
  • 10
  • 18