All Questions
144 questions
0
votes
1
answer
30
views
Cannot place math text (plotmath) in geom_table
The error
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘"expression"’ to a data.frame
occurs when creating a legend for geom_table():
# making table legend
...
0
votes
1
answer
42
views
What does annotate() shift over my geom_text() in ggplot2 when using rich text?
I have 2 plots that I'm joining together. The top shows the raw data and the second is a subjective rating. The issue is that when I try to have a label using annotate() with rich text explaining what ...
0
votes
1
answer
76
views
Text outside the plot; how to add add a paragraph, selectively bold, and save plot with annotations
I am trying to edit text outside a plot, below the legend. I've followed the instructions suggested here and I've been able to put together the following code
p <- ggplot(Amh2, aes(x=syllable, y=...
0
votes
1
answer
57
views
ggplot2 faceting and adding unique labels for each facet in a for loop in R
I am trying to add a unique label to each faceted panel in my plots. Below is the code which I annotated and will describe in detail below:
ebird <- left_join(ebird, cor,
by = ...
1
vote
1
answer
39
views
ggplot2 text in top margin, flipped coordinates
I would like to add some text to a plot in the top margin, but all the solutions I could find messed up the flipped coordinate system after using coord_flip()
var1<- c("ab", "cd"...
0
votes
0
answers
19
views
Adding table to one plot of facet_grid ggplot [duplicate]
I'm trying to add a table to the plotting region of one plot that is part of a larger facet_grid ggplot. My question is very similar to an earlier question, except I only want a plot on panel "A&...
0
votes
0
answers
29
views
Defining y value within annotate as value in column after selectInput
I have a plot for each category that can be selected via selectInput. In each plot, there is a horizontal line that indicates the control mean. The height of this line changes for each category. The ...
0
votes
1
answer
91
views
Use hover inputs to annotate a ggplot in Shiny?
I am working on Shiny app. One of the plots in my app is an area plot of Chicago evictions over time. I have permanent annotations on the plot for the peak and most recent values in the data (2012 and ...
1
vote
1
answer
37
views
Plot arrow outside of figure instead of inside
I am trying to plot the arrow outside of the figure. I have tried a number of different options, but they keep plotting the arrow inside the figure. Is there a way to plot it outside the bounding box?
...
1
vote
1
answer
201
views
How to add multiple labels to faceted ggplot outside of the plot?
I use facet_rep_grid to visualize different variables over the same x-axis. Now I would like to label the top left of each facet with "A", "B", "C" etc.
what i have looks ...
1
vote
1
answer
45
views
annotate box to follow legend position ggplot2
My data:
plot_data <- structure(list(date = structure(c(18993, 18994, 18995, 18996,
18997, 18998, 18999, 19000, 19001, 19002, 19003, 19004, 19005,
19006, 19007, 19008, 19009, 19010, 19011, 19012, ...
0
votes
1
answer
559
views
Multiple points with same label in ggrepel - avoid redundant labels
I want to annotate a scatterplot with several points that have the same label. I want to label all of them (not just a part of them) but it is a mess with so many redundant labels.
Is there any way to ...
1
vote
1
answer
41
views
Annotate text on individual facet multiple times
I came from this post answering on how to add text to text to the plot. However, my problem goes beyond because I need to add text multiple times in multiple locations. The annotate functions seems ...
1
vote
1
answer
196
views
Customizing look of table inserted into a ggplot
I want to annotate a table to an existing ggplot with a specified theme.
However, I'd like to adapt the look of the table and change the color of the gridlines and the background color of the table ...
0
votes
1
answer
61
views
How to plot results from median_test using ggplot annotate in R?
I have a simple set of data (length of stay in hospitals) which is separated by "Low" and "Normal" groups.
The median is the statistic used to represent this data and I'd like to ...
0
votes
1
answer
52
views
Place (x,y) coordinate pairs in ggplot annotation label
I have a ggplot I'm using to illustrate some trig concepts via an RMarkdown document.
annotate("text",
x = 0.97,
y = 0.5,
label = str_c("(~frac(...
2
votes
1
answer
128
views
How to resolve this waring: is.na() applied to non-(list or vector) of type 'expression'?
The following R code
library(ggplot2)
ggplot() +
annotate("text", x = 1, y = 1, label=expression(paste("model 1, ", italic(R)^2, ": 0.50")),
size = 14/.pt, col='...
0
votes
2
answers
298
views
ggplot add date labels to x axis whilst using numeric x values
I would like to reproduce the following plot, but I would like to add date labels every 4 months instead of numeric.
I had to convert the date_time values to numeric in order to plot the annotate(&...
0
votes
1
answer
39
views
Annotating only unique duplicated key values on a diverging bar chart in ggplot2
Say I have a dataframe (df) with a total of 2 columns and 40 rows. The first column have duplicated key/ID values and the second contains 20 positive values, followed by 20 negative ones.
Because of ...
0
votes
1
answer
155
views
Avoid cut geom_label() with facet_wrap()
in the plot below I have data distributed into four groups separated via facet_wrap(). However, these groups have an uneven distribution of the data, hence, all groups have different bar sizes.
How ...
1
vote
0
answers
551
views
How to add a rectangle to a ggplot graph with a logged y-axis without changing the y-axis scale
I am trying to add a rectangle to a ggplot graph with a logged y-axis using annotate() or geom_rect(). The rectangle is bounded by two x-axis values (which are dates) and needs span the enitre y-axis. ...
0
votes
1
answer
207
views
Multiple titles/labels on y-axis in ggplot2
I have a data frame that looks like this:
variable <- c("Financial wealth", "Financial wealth", "Financial wealth",
"Financial wealth", "...
0
votes
2
answers
1k
views
Annotate ggplot with multiple coloured text annotations the same as the legend / plot features
I'm trying to annotate a ggplot that shows multiple results of the same response on different days. When I plot the data, I set col = day in the aes command. How do I annotate the ggplot with mean ...
2
votes
1
answer
501
views
Wrapped Caption on Arranged Plot
I am trying to put 4 plots together and add a long caption (Figure caption) underneath of the plots. However, when I try to add the caption, it puts the wrapped caption over top of the graphs. ...
0
votes
0
answers
255
views
R ggplot2 annotate fails
I have a script in R that is doing a print of graphics automatically in form of a loop. I try to implement into the ggplot an annotation using annotate. But it doesn't work.
Here's the code:
sp<-...
0
votes
1
answer
35
views
Multiple graphs have problem when use annotate
I have a data set (generated as below) and made 3 graphs G1, G2, G3 (codes are below). When I print a graph after creating it there is no problem. However, If I print them after all of them created, ...
0
votes
1
answer
105
views
ggplot annotate brakes axis
I want to insert a text into my ggplot chart. The text got a subscript and a supersubscript like X[X} = 1,00*Y R^2 = 0,90. For that I used the function paste(expression()) into annotate(label=()).
In ...
1
vote
1
answer
379
views
Left alignment title in arrange function in R
How do I adjust the title to the left? And also, in the annotate_figure can I create a subtitle? Instead of cutting the line \n, as I don't want the subtitle in bold.
I am using the arrange function ...
0
votes
1
answer
86
views
Adding text in one of the four facets [duplicate]
I want to add a few texts in one facet out of four facets in my ggplot.
I am using annotate function to add a text but it generates the text at a given location (x,y) in every facet. Because the data ...
2
votes
1
answer
193
views
Annotating an existing ggplot2
I ran into problems with annotating to an existing ggplot2 using the
plotname + annotate()
syntax
I was trying to annotate to an existing ggplot using a loop which aims to add text and arrows to a ...
0
votes
0
answers
109
views
ggplot2: How do I colorize elements of a table within a plotarea?
I made a bar plot with ggplot2 that contains a data table within its plot area. How can I colorize text elements within this data table?
I know how to colorize text with "geom_richtext", but ...
0
votes
1
answer
170
views
How i put R for pearson correlation in italic font inside an annotate function in ggplot?
i used iris data for an example
`
iris %>%
ggplot(aes(Sepal.Length,
fill = Species))+
geom_density(alpha = .6,
bw = 0.5)+
theme_classic()+
annotate(&...
0
votes
1
answer
97
views
R annotate estimates with p < 0.05
This is an extension of my old question on the topic of error bars. Suppose this is my test data.
df1<-"Group Est conf.low conf.high pvalue
Bi 1.12 0.65 ...
1
vote
1
answer
229
views
Adding a black outline for each x category in heat map in R
Here is my data which produces a heat map. What I am hoping to do is produce multiple difference heatmaps with an outline around each of x categories.
data <- data.frame(id=c("john","...
1
vote
1
answer
424
views
Dynamic vlines and annotations on ggplot
I was wondering if it's possible to dynamically generate geom_vlines and annotations for a ggplot based on the contents of another dataframe.
I currently have a dataframe of the following structure, ...
3
votes
2
answers
170
views
Vectorizing R expression
I am trying to vectorize the title and subtitle of a figure within the R expression using atop() function as in the example below with no success. Could anyone help me with this?
title = "Text ...
1
vote
1
answer
338
views
Plus minus label using \u00B1 and $+-$ does not work on my annotation in ggplot
I've seen similar questions posted on this and using \u00B1 has worked in the past but now this does not work anymore.
avg1<- c(expression(paste("22.2 ","\u00B1", " 0.83&...
0
votes
3
answers
510
views
Annotation label clipped in ggplot2
I'm trying to avoid the bottom annotation being clipped. It's the descender on the "p" that gets chopped off. I've used the "inward" option on vjust.
df <- data.frame(x=c(as....
0
votes
1
answer
637
views
ggplot annotate each facet with different geom_rect dimensions
I am trying to annotate each facet of my ggplot with a different geom_rect object.
Reproducible example:
a <- c(x= rnorm(30, mean = 100, sd=2))
b <- c(rep(c("X", "Y"), 30))
c ...
1
vote
1
answer
450
views
Plot single block of color in R
I am trying to figure out how to plot a single block of color in R. I am trying to visualize a region of a genome with color. I am starting with a matrix that has 1 row and 6049 columns.
l1_canon <-...
1
vote
2
answers
1k
views
How do I add a legend based to my scatterplot based on annotate("rect")?
I have created a scatterplot using ggplot2 in RStudio with the function annotate("rect".... to add a layer of colours based on another variable. I have been trying to add a legend for SO ...
0
votes
1
answer
597
views
Symbol lambda (λ) is not showing up when exporting image as PDF in R?
I created a figure in R using ggplot2, and using annotate I included a lambda (λ) symbol in the text. However, when I do Export > Save as PDF, the PDF image does not show the lambda and instead ...
0
votes
2
answers
218
views
Error when looping with lapply to add text with value from one column in a ggplot
I am following up my last question here because I got a bit greedy and I wanted to add something more to my plots so I decided I would create a new post.
So to summarize I wanted to make several plots ...
1
vote
1
answer
3k
views
ggplot2 add geom_text on geom_col layer with labels data.frame
I have a bar plot with position = fill to show proportions with 2 colors on the same column. I'm trying to add a geom_text layer on this graph to show ho many genes out of the total genes are making ...
2
votes
2
answers
425
views
How to get rid of annotations on faceted graph?
Problem
I am trying to label the left facet side of my graph while leaving out the annotations on the right side.
Data
Here are my libraries and data:
#### Libraries ####
library(tidyverse)
library(...
0
votes
2
answers
823
views
All of my ggplot annotations disappear when adding a picture using inset_element?
I am working on a plot that will have the data curve, a png image inset, as well as annotations. However, every time I add my inset image all of my annotations disappear and I'm not sure what I am ...
0
votes
1
answer
351
views
How to make an annotation layer relative to a geom_point layer
I would like the annotated text on this chart to be relative to the data points on the line chart because this report is parameterized so the points change with each iteration. How do I make the ...
0
votes
2
answers
1k
views
How can I write an equation with superscripts using annotate in ggplot2?
I am having trouble figuring out how to write out an equation using annotate in ggplot2.
Here is an example of what I want to get, I just can't figure out how to get the superscripts in the equation ...
0
votes
2
answers
70
views
How to fix problem with "for" in the ggplot2 label
I'm trying to make a plot with facets and add annotations in each of the facets.
I want the annotations to look like "p for trend=0.001" like the plot such as this image.
The plot I made ...
3
votes
1
answer
2k
views
Annotating a rectangle in R with ggplot2 for a graph in log scale
I'm trying to annotate a rectangle in R through ggplot2 for a graph that is in log scale. Here's the annotate layer I am adding:
annotate("rect",xmin=293.3, xmax=312, ymin=-Inf, ymax=Inf, ...