[英]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. 我有100种聚合物,每种聚合物都有20个数据点(x,y)绘制曲线。 I used R Shiny to interactively select one or more polymers to plot.
我使用R Shiny交互式地选择一种或多种聚合物进行绘图。 Everything works fine when I used ggplot2 to plot.
当我使用ggplot2进行绘图时,一切正常。 Since plotly is able to do tooltip, I converted ggplot2 to plotly using something like
由于plotly可以执行工具提示,因此我将ggplot2转换为使用以下方法
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.
每当我选择某种聚合物(称为BadGuy)时,曲线就会混乱。
Before selecting BadGuy, the curves are neat. 选择BadGuy之前,曲线要整齐。 Before selecting BadGuy
选择BadGuy之前
But after selecting BadGuy, the curves messed up. 但是选择BadGuy之后,曲线变得混乱了。 After selecting BadGuy
选择BadGuy之后
Everything works fine if just using ggplot2, no matter selecting or not selecting the BadGuy. 如果仅使用ggplot2,则一切正常,无论是否选择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
我必须在使用plotly进行绘图之前对数据进行排序,即使对于ggplot2而言也没有必要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.