简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM