You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug with Date Format in plotly on LINUX from ggplot conversion to PLOTLY #482
I moved my code from Windows to Linux R/Shiny server and I noticed that the same exact code that displays the proper DATE format in Windows shows as a different Date Time format on Linux. It seems that when I convert the ggplot to PLOTLY using ggplotly(), it behaves differently with the Date format than in Windows.
Here is the sample code:
p1 <- ggplot() + geom_smooth(
method = gam,
formula = y ~ s(x,bs="cc",k=12),
data = test2 ,
aes(x = DT_STAY_DATE, y = test2[, input$yvar_p] , color = PROPERTY_NAME)
) + ylab(input$yvar_p)
ggplotly(p1)
I moved my code from Windows to Linux R/Shiny server and I noticed that the same exact code that displays the proper DATE format in Windows shows as a different Date Time format on Linux. It seems that when I convert the ggplot to PLOTLY using ggplotly(), it behaves differently with the Date format than in Windows.
Here is the sample code:
p1 <- ggplot() + geom_smooth(
method = gam,
formula = y ~ s(x,bs="cc",k=12),
data = test2 ,
aes(x = DT_STAY_DATE, y = test2[, input$yvar_p] , color = PROPERTY_NAME)
) + ylab(input$yvar_p)
Hi, thanks for the update on the Update. I am new to plotly so bear with me as I have 2 questions:
Does downloading from the developer tool via "devtools::install_github("ropensci/plotly")" ensure that I have the latest code case from github? Is there a direct pull from github that I need to do to get this latest update.
I did try doing the update via "devtools::install_github("ropensci/plotly")" to see if it resolves the above issue. I now see the SCROLLING LEGEND (which is great)...but the X Axis DATE TIME stamp issue still persists. Again, I do NOT see this issue on Windows. Why does GGPLOTLY lose my DATE values on the X axis. As you can see, because of this the 2 data sets are disjointed which is not what I want.
I also confirmed this is unrelated to my specific code. On LINUX, for some reason if I have a DATE X axis on a ggplot geom, PLOTLY does not retain that format when I do plot_ly or ggplotly(). However, this is not an issue on Windows.
Here is a simple example of the problem using the ECONOMICS data set.
t <- ggplot(economics, aes(date, pop))
t + geom_point()
ggplotly()
When I convert via GGPLOTLY notice the X AXIS is now showing DATETIME which I do not want.
devtools::install_github("ropensci/plotly") installs the master branch. You can install the dev branch that will fix this with devtools::install_github("ropensci/plotly@rewrite")
Thanks you. I installed the DEV branch and the issue is indeed resolved now.
However, it seems that it also impacted my second data set from add_trace (diamonds representing events) disappear. Does the new code impact how I added a trace to my existing plotly. Here is my code...The X axis date is fine now but the add_trace points are gone.
Here is my code snippet of how I am adding a trace to my original geom_smooth:
Unlike before, you will need to specify all the aesthetics in each trace like so:
library(plotly)
p <- plot_ly(economics, x = date, y = uempmed, name = "unemployment")
p %>% add_trace(x = date, y = fitted(loess(uempmed ~ as.numeric(date))))
I tried this suggestion for my example but it does not work as expected. Note that in my case..the GGPLOT converted to PLOTLY uses a completely different Data Set than the ADD_TRACE. Basically, I am overlaying 2 different data sets and using a second Axis Y2.
This worked fine with the previous MASTER build but does not with the DEV branch. Any idea what I am missing here:
Here is my code:
p1 <- ggplot() + geom_smooth(
method = gam,
formula = y ~ s(x,bs="cc",k=12),
data = test2 ,
aes(x = DT_STAY_DATE, y = OCCUPANCY , color = PROPERTY_NAME))
Is there a way for me to just get the FIX for the LINUX DATE issue...versus the full DEV build? We cannot proceed with using Plotly if it cannot allow the overlay and dual legend/axis across the GEOM and the ADD_TRACE Markers as before. I hope the new build does not limit that functionality as that was one of the most important features of Plotly for us. Any insight is appreciated.
Here is mock data for test2. I dont think you are trying what I am trying. You can execute the exact same code for test2 and ATLevents and you should be able to reproduce the issue.
Awesome....that worked and I see the markers. 2 follow up items:
I also see a milliseconds as I scroll on the plot for the X axis. Is there a way to override this behavior to show the actual dates. Would scale_x_date work?
I also see that my Legend placement is no longer working so I may have to play around with that. I explicitly positioned the legend to show at the bottom to not cover the Y2 Right side axis but seems that does not render as expected.
Activity
ahsanshah commentedon Mar 6, 2016
Hi, thanks for the update on the Update. I am new to plotly so bear with me as I have 2 questions:
I also confirmed this is unrelated to my specific code. On LINUX, for some reason if I have a DATE X axis on a ggplot geom, PLOTLY does not retain that format when I do plot_ly or ggplotly(). However, this is not an issue on Windows.
Here is a simple example of the problem using the ECONOMICS data set.
When I convert via GGPLOTLY notice the X AXIS is now showing DATETIME which I do not want.
cpsievert commentedon Mar 6, 2016
devtools::install_github("ropensci/plotly")installs the master branch. You can install the dev branch that will fix this withdevtools::install_github("ropensci/plotly@rewrite")ahsanshah commentedon Mar 7, 2016
Thanks you. I installed the DEV branch and the issue is indeed resolved now.
However, it seems that it also impacted my second data set from add_trace (diamonds representing events) disappear. Does the new code impact how I added a trace to my existing plotly. Here is my code...The X axis date is fine now but the add_trace points are gone.
Here is my code snippet of how I am adding a trace to my original geom_smooth:
output$vis_p <- renderPlotly({
It seems that PLOTLY is ignoring my add_trace POINTS as well as Y AXIS on the left..but it does show the LEGEND.
Thoughts? I can raise a separate case for this if that works better.
ahsanshah commentedon Mar 7, 2016
I cofirmed the new DEV build has an issue with ading a trace to an existing graph.
Here is a simple example which I found online which shows the same issue I am facing with code above.
p <- plot_ly(economics, x = date, y = uempmed, name = "unemployment")
p %>% add_trace(y = fitted(loess(uempmed ~ as.numeric(date))))
In the previous MASTER Build:
In the new DEV build:
The above behavior is impacting my existing ggplot + add_trace as I cannot see the markers on the add_trace, Please advise.
royr2 commentedon Mar 7, 2016
Unlike before, you will need to specify all the aesthetics in each trace like so:
ahsanshah commentedon Mar 7, 2016
I tried this suggestion for my example but it does not work as expected. Note that in my case..the GGPLOT converted to PLOTLY uses a completely different Data Set than the ADD_TRACE. Basically, I am overlaying 2 different data sets and using a second Axis Y2.
This worked fine with the previous MASTER build but does not with the DEV branch. Any idea what I am missing here:
Here is my code:
p1 <- ggplot() + geom_smooth(
method = gam,
formula = y ~ s(x,bs="cc",k=12),
data = test2 ,
aes(x = DT_STAY_DATE, y = OCCUPANCY , color = PROPERTY_NAME))
p_gg<- ggplotly(p1)
p_gg %>% add_trace(
x = startlocal,
y = events.capacity,
mode = "markers",
marker = list(size=12,symbol=2),
yaxis = "y2",
opacity = .7,
data = ATLevents,
text = paste0( "",
nametext,
"
",
"Capacity : ",events.capacity,
"
",
"Duration : ",duration,
"
",
"Category : ",categories.name
),
name = "Events",group = categories.name
) %>%
layout(yaxis2 = list(side = "right", overlaying = "y"),
showlegend = "TRUE",
title="Events & Demand",
width = 1000, height = 600,
margin = list(l=75,r=75,b=200,t=50,pad=5),
legend=list(x=1, y=0,
font=list(family = "sans-serif",
size = 9,
color = "#000"))
)
This is how it looks prior to the new DEV BUILD:
This is how it looks with the NEW DEV BUILD:
ahsanshah commentedon Mar 7, 2016
Also...the Y and X axis seem to be overlapping with the values....this was not an issue with the prior MASTER build.
Let me know if this is a bug or I need to do something to correct this. Adding the aesthetic on ADD_TRACE does not seem to help in this case.
ahsanshah commentedon Mar 7, 2016
Is there a way for me to just get the FIX for the LINUX DATE issue...versus the full DEV build? We cannot proceed with using Plotly if it cannot allow the overlay and dual legend/axis across the GEOM and the ADD_TRACE Markers as before. I hope the new build does not limit that functionality as that was one of the most important features of Plotly for us. Any insight is appreciated.
cpsievert commentedon Mar 7, 2016
Can you provide test2 and ATLevents?
ahsanshah commentedon Mar 7, 2016
I canb provide ATLevents but test2 data I cannot as it is internal system data which is secure. However, I can provide the str output for TEST2.
All I am using is DT_STAY_DATE as the X axis on the GEOM.
I attached the ATLevents RDS..
ATLevents.zip
Here is the str for ATLevents:
Thanks
cpsievert commentedon Mar 7, 2016
If I can't reproduce your example, there's no guarantee I can't fix it.
This works for me, so I'm not sure why the second trace isn't showing up.
I'm pretty sure you'll have to move the legend position to the right for the second axis to appear
ahsanshah commentedon Mar 7, 2016
Here is mock data for test2. I dont think you are trying what I am trying. You can execute the exact same code for test2 and ATLevents and you should be able to reproduce the issue.
Thanks
test2.zip
ahsanshah commentedon Mar 7, 2016
Confirmed with the 2 data sets I sent that I can reproduce the issue:
cpsievert commentedon Mar 7, 2016
Ah, the ggplot converter now converts dates/datetimes to the number of milliseconds since the UNIX epoch before sending to plotly.
Change this line:
to
ahsanshah commentedon Mar 8, 2016
Awesome....that worked and I see the markers. 2 follow up items:
Any thoughts on these 2 items ?
Regardless, thanks for your assistance.