I created a plotly scatterplot in R on which I would like to add a polygon.
This is the code I used to make the graph:
fig <- plot_ly(data = data, x= ~xbeak, y = ~ybeak, color = ~coordsbeak, text = ~paste(coordsbeak), type = 'scatter')
Now I want to add a polygon to this plot, which I tried with add_polygons. The polygon is a different dataframe, consisting two columns with 42 x and y coordinates.
fig <- fig %>% add_polygons(x = xym$x, y=xym$y)
However when I try to run this I get this error which I don't understand. Any idea what I'm doing wrong?
Error: ! Tibble columns must have compatible sizes. • Size 42: Columns
x
andy
. • Size 11149: Columnstext
andcolor
. ℹ Only values of size one are recycled. Runrlang::last_error()
to see where the error occurred.