Skip to content

Plot annotation outside plot region in a shiny app  #4219

@dancelestini

Description

@dancelestini

How can I show the name of the dotted red line underneath the x axis ? I would like to put the name of this vertical line at the same level of the date or maybe lower. Maybe the annotate element is not the right one but with "geom_text" it's even worst. Here is the shiny app in question where I just don't put the names of this line.
https://dancelestini.shinyapps.io/Swiss-COVID19/

image

library(tidyverse)
library(readxl)
library(plotly)
library(ggplot2)

df = read_excel("covid-19.3.xlsx", sheet = 1)

df$Date = as.Date(df$Date,format = "%Y-%m-%d")

p = ggplot(data = df, aes(Date, `Nombre de cas`))+
  geom_col(size = 0.1)+
  labs(title = "Swiss COVID-19 cases per day",y="New observation per day", x = "Date")+
  theme(plot.title = element_text(hjust = 0.5, color = "red", size =14, face="bold.italic"),
        axis.title = element_text(face = "bold"),
        plot.margin = margin(20,20,20,20, unit = "pt"))+
  geom_vline(xintercept = as.numeric(as.Date("2020-05-11")), color = "red", linetype = "dotted", size = 0.5)+
  annotate("text",x=as.Date("2020-05-11"),y = -100,label = "name",color = "black",size = 5)+
  coord_cartesian(clip = "off")
  
ggplotly(p)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions