How can I remove duplicate labels produced by geom_text on each faceted plot?
<p>I need to produce a facetted plot that shows transactions along a time axis. In addition, there are certain time stamps that I want to mark with a vertical line across all the facets.</p>

<p>I have managed to produce a plot like the one below, which shows the labels / markers (v4.6.3, v5.0.3, v5.2.3) in a pretty way. However, it draws them on each facet, which I want to avoid; and even worse, the labels overlap with the facet above.</p>

<p><a href="https://i.stack.imgur.com/6fjG2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6fjG2.png" alt="Facetted ggplot2 plot with duplicate labels."></a></p>

<p>I have tried to tackle this using <code>geom_label</code>, but this only leads to a different set of problems (e.g. no 45 degree angle).</p>

<p><em>How can I remove all these labels except for the topmost facet?</em></p>

<p>Please find below a code snippet that should allow one to reproduce the plot.</p>

<pre><code>if (!require("pacman")) install.packages("pacman")
library("pacman")
pacman::p_load(plyr, reshape2, ggplot2, lubridate, stringr, grid, gridExtra)


df &lt;- structure(list(instantId = structure(c(1184065080, 1184065080,
1184065082, 1184065080, 1184065084, 1184065084), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), layerId = c("application", "application",
"application", "infrastructure", "infrastructure", "infrastructure")), .Names = c("instantId",
"layerId"), row.names = c(NA, 6L), class = "data.frame")

dfMarkers &lt;- structure(list(version = c("v4.6.3", "v5.0.3", "v5.2.3"), releaseDate = structure(c(1184065081,
1184065083, 1184065085), class = c("POSIXct", "POSIXt"
), tzone = "UTC")), .Names = c("version", "releaseDate"), row.names = c(NA,
3L), class = "data.frame")


RenderTransEvo &lt;- function(df, dfMarkers, boCumulative = FALSE) {
    df &lt;- plyr::count(df, vars = c("layerId","instantId"))
    p &lt;- ggplot(df, aes(instantId)) +
        scale_x_datetime(expand = c(0.0, 0)) +
        theme(plot.margin = unit(c(1,0.1,0.1,0.1),"cm"),
              panel.grid.major.y = element_blank(),
              panel.grid.minor = element_blank(),
              axis.title = element_blank(),
              axis.text.x = element_text(angle = 45, hjust = 1))

         p &lt;- p + geom_area(aes(y = freq)) + facet_grid(layerId ~ ., scales = "free_y", space = "free_y")

        p &lt;- p + geom_vline(color = "blue",
                            xintercept = as.numeric(dfMarkers$releaseDate),
                            linetype = 2,
                            size = 0.25) +
                  geom_text(data = dfMarkers,
                            mapping = aes(x = releaseDate, y = Inf, label = paste0(" ", version)),
                            check_overlap = TRUE,
                            size = 3, angle = 45, vjust = 0, hjust = 0)

  gt &lt;- ggplot_gtable(ggplot_build(p))
  gt$layout$clip[gt$layout$name == "panel"] &lt;- "off"
  grid.draw(gt)
}
RenderTransEvo(df,dfMarkers)
</code></pre>