0

In a Rmarkdown document, when I use ggplot to plot data (a map in my case) and label points with geom_text_repel from the ggrepel package, the labels disappear when I open the plot in the Rstudio: Notebook output (show in new window). I would like to be able to quickly have a look at my labeled plot and enlarge it with the notebook output view.

Is that a bug in ggrepel, ggplot, Rmarkdown or Rstudio? Can I get rid of it?

I am using Rstudio Version 1.1.453, R version 3.6.2 under Linux Mint. The error persists with Rstudio Version 1.2.5033

Package versions:

> packageVersion("ggplot2")
[1] ‘3.2.1’
> packageVersion("ggrepel")
[1] ‘0.8.1’
> packageVersion("sf")
[1] ‘0.8.1’
> packageVersion("rnaturalearth")
[1] ‘0.1.0’
> packageVersion("rnaturalearthdata")
[1] ‘0.1.0’
> packageVersion("rmarkdown")
[1] ‘2.1’
> packageVersion("knitr")
[1] ‘1.28’

MWE:

---
title: "Test"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library("ggplot2")
library("ggrepel")
library("sf")

library("rnaturalearth")
library("rnaturalearthdata")

world <- ne_countries(scale = "medium", returnclass = "sf")


label <- c(30, 38,39,132-2)
latitude <- c(-55.8,-58.7,-59.3,-52.6)

longitude <- c(-71.3, -68.4,-67.2,-75.5)
df <- data.frame(latitude, longitude, label)

p <- ggplot(data = world) +
  geom_sf() +
  coord_sf() +
  geom_point(data = df, aes(x = longitude, y = latitude))+
  geom_text_repel(data = df, aes(x = longitude, y = latitude, label = label))

show(p)
```

screenshot - labels disappeared in the new window (visible in the chunk output)


"Update" A similar, maybe related (?) behaviour happens, when I want to draw a grid grob with grid.draw. This only happens within output view of the chunks (and related "show in new window" option) rmarkdown files. When I run the same code from an R script, the Viewer-Windows shows the output just as expected.

This (both) seem to be a Rstudio bug related to Rmarkdown documents and specifically the output-view of chunks.

Nele
  • 31
  • 5
  • cannot replicate the error. Which package versions do you use? – mnist Feb 24 '20 at 14:39
  • @mnist I updated the post and uploaded a screenshot – Nele Feb 24 '20 at 15:19
  • ah okay now I see what you mean! Its actually the same for me. I can see the labels quickly but then they disappear as soon as the plot is completely rendered. Looks like a bug^^ – mnist Feb 24 '20 at 16:06
  • I can't replicate this. What versions of rmarkdown and knitr do you have? – Phil Feb 24 '20 at 16:24
  • @Phil see post update – Nele Feb 24 '20 at 16:46
  • I wonder if the issue is a missing LaTeX package. Are you using MikTeX or MacTeX? Or TinyTex? – Phil Feb 24 '20 at 17:10
  • that would be odd, since this happens unrelated to knitting. In the knitted pdf it is just fine. I use TexLive. – Nele Feb 24 '20 at 17:29
  • Sorry, I think I misunderstood. What if you update RStudio to its [latest stable release](https://rstudio.com/products/rstudio/download/#download) (v1.2.5033)? Or its [preview release](https://rstudio.com/products/rstudio/download/preview/) (v1.3.820)? – Phil Feb 24 '20 at 17:52
  • @Phil I updated to the latest stable release - the disappeance still happens – Nele Feb 25 '20 at 14:48

0 Answers0