简体   繁体   English

使用ggplotly将ggplot2转换为plotly时,曲线混乱

[英]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.

相关问题 R plotly:用ggplotly转换ggplot2时,保留两个图例的外观 - R plotly: preserving appearance of TWO legends when converting ggplot2 with ggplotly 使用 ggplotly(ggplot2 with plotly)时,你能去掉注释中的跟踪标签吗? - Can you get rid of the trace labels in the annotations when using ggplotly (ggplot2 with plotly)? 使用ggplot2和ggplotly创建Sankey Diagram - Creating Sankey Diagram using ggplot2, plotly and ggplotly R plotly:使用ggplotly()时如何保持ggplot2 geom_bar()的宽度参数 - R plotly: How to keep width parameter of ggplot2 geom_bar() when using ggplotly() 如何在使用`ggplotly`将ggplot2转移到图表时更改图例位置? - How to change the legend position when transfer ggplot2 to plotly using `ggplotly`? ggplot2和ggplotly之间的行为不同 - Different behavior between ggplot2 and plotly using ggplotly 将 ggplot2 转换为 ggplotly 时缺少 geom_rect - geom_rect missing when converting ggplot2 to ggplotly 使用ggplotly时,不会解析ggplot2图形中的标签(注释) - Labels (annotate) in ggplot2 graphics are not parsed when using ggplotly 在R中以绘图方式在子图之间共享轴和图例(ggplot2中的构面和使用ggplotly不起作用) - Sharing axes and legends between subplots in plotly in R (faceting in ggplot2 and using ggplotly doesn't work) 无法使用 ggplotly 转换 ggplot2 - Unable to convert ggplot2 using ggplotly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM