Vera0816
Vera0816

Reputation: 23

curves messed up when converting ggplot2 to plotly using ggplotly

I have 100 kinds of polymers and each polymer has 20 data points (x, y) to plot a curve. I used R Shiny to interactively select one or more polymers to plot. Everything works fine when I used ggplot2 to plot. Since plotly is able to do tooltip, I converted ggplot2 to plotly using something like

p = ggplot(subdata, aes(x = x, y = y, colour = polymer) + geom_line() + geom_point() + scale_x_log10() + scale_y_log10() +  theme() 
ggplotly(p)

Now problem happens. Every time once I selected a certain polymer (call it BadGuy), the curves mess up.

Before selecting BadGuy, the curves are neat. Before selecting BadGuy

But after selecting BadGuy, the curves messed up. After selecting BadGuy

Everything works fine if just using ggplot2, no matter selecting or not selecting the BadGuy. I guess it is the convert causing this problem, but I do not know how to solve it.

Thanks!

Upvotes: 1

Views: 188

Answers (1)

Vera0816
Vera0816

Reputation: 23

I figured it out later. I have to sort the data before plotting using plotly even though it is not necessary for ggplot2

Upvotes: 0

Related Questions