0
votes

I'm trying to add a caption to a basic plot_ly to include more information about the scatter plot I have.

I've had a look at this thread: plotly adding a source or caption to a chart but the caption here is inline with the x-axis title.

I can't seem to get the caption underneath the plot and x-axis title.

1
See here on making an R question that's easy for folks to help with. That includes code you've tried already, any necessary data, and a clear sense of what you're trying to do - camille

1 Answers

2
votes

Starting with the post you link to, you need to set the margin in the plot_ly layout and then change the x, and y in the annotations

library(plotly)
plot_ly(x=~hp, y=~mpg, data=mtcars, type="scatter", mode="marker") %>% 
  layout(margin = list(b=160), ##bottom margin in pixels
         annotations = 
           list(x = 0.5, y = -0.75, #position of text adjust as needed 
                text = "Source: data I found somewhere.", 
                showarrow = F, xref='paper', yref='paper', 
                xanchor='right', yanchor='auto', xshift=0, yshift=0,
                font=list(size=15, color="red"))
  )

enter image description here