I'm using plotly in R, though I don't think it should matter. Basically, I want to draw a line plot of a set of points that don't correspond to a function (in the mathematical sense). See the below code for a simple example, I think it's fairly obvious what the problem is. I want the second plot to simply look like the first one inverted across the x/y axes.
To clarify, the example below could be solved be using the inverse function (square root), but I'm looking for a generic solution that doesn't rely on having an explicitly invertible function.
library(plotly)
library(magrittr)
x <- seq(from=-2, to=2, length.out = 200)
y <- x^2
p1 <- plot_ly() %>%
add_lines(x=x, y=y)
p2 <- plot_ly() %>%
add_lines(x=y, y=x)


