0

I've made a function that outputs a graph. I can add an annotation to it just fine, but if I try to add two annotations in a list (which is what the documentation tells me to do), the whole plot disappears.

Here is code that works:

a <-  list(
    x = 0,
    y = 1.05,
    text = 'Quotes',
    xref = "paper",
    yref = "paper",
    showarrow = F
  )
  
  b <-  list(
    x = 1,
    y = 1.05,
    text = 'Sales',
    xref = "paper",
    yref = "paper",
    showarrow = F
  )

function1(dt) %>% 
  layout(annotations = a)

function1(dt) %>% 
  layout(annotations = b)

But if I run the below line, the whole plot goes blank (no axes or anything):

function1(dt) %>% 
  layout(annotations = list(a,b))

Has anyone come across this problem before? Any help gratefully appreciated.

Hebe
  • 1
  • 1
    Welcome to SO! Would you mind providing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including the code of your function `function1` and a snippet of your data or some fake data. – stefan Dec 20 '21 at 17:53
  • ... this said: Your code works fine when I test on a simple scatterplot `function1 <- function(dt) plot_ly(dt, x = ~x, y = ~y, type = "scatter", mode = "markers")` and making use of some simple fake data `dt <- data.frame(x = seq(0, 1, length.out = 10), y = seq(0, 1, length.out = 10))`. – stefan Dec 20 '21 at 17:54
  • Ah, I used the dataset you just made and I still get a blank plot. Do you think it's maybe just some glitch with my version of R? My friend ran my code and experienced the same problem. – Hebe Dec 20 '21 at 19:07
  • Hm. Always my first option: Restart R. Run the code again. (: Second I would check `packageVersion("plotly")`. Mine is `4.10.0`. – stefan Dec 20 '21 at 19:24
  • Ah. My plotly is only 4.5.2! It seems to be the most up-to-date I can get with my work's version of RStudio (1.0.136). Huh oh well maybe I can find some really offensive work-around for my double annotation. Thank you for your help though – Hebe Dec 21 '21 at 22:16

0 Answers0