Skip to content

ggplotly - date scale not in limits and linechart data inaccurate #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aylon1 opened this issue Jan 23, 2016 · 1 comment
Closed

ggplotly - date scale not in limits and linechart data inaccurate #422

Aylon1 opened this issue Jan 23, 2016 · 1 comment

Comments

@Aylon1
Copy link

Aylon1 commented Jan 23, 2016

Hello and thenks for the great tool that plotly is!

I am using the code from https://plot.ly/ggplot2/scale_x_date/#stock-chart-prices-dashboard with function call

gg.charts.PerformanceSummary(port.data$returns, main=paste("Summary" , sep= " - "), plot = T)

the ggplot is slightly amended

gg.xts <- ggplot(df, aes_string( x = "Date", y = "value", group = "variable" )) +
facet_grid(variable ~ ., scales = "free_y", space = "fixed") +
geom_line(data = subset(df, variable == "Index")) +
geom_bar(data = subset(df, variable == "Return"), 
         stat = "identity", 
         position = "identity") +
geom_line(data = subset(df, variable == "Drawdown")) +
geom_hline(yintercept = 0, size = 0.5, colour = "black") +
ggtitle(title.string) +
theme(axis.text.x = element_text(angle = 0, hjust = 1)) +
scale_x_datetime(date_breaks = "12 months", 
                 labels = date_format("%m/%Y"), 
                 limits = as.POSIXct(c(first(df$Date),last(df$Date)))) +
ylab("") +
xlab("")

and produces the correct result with a distinct negative performance as seen below

image

running then ggplotly() creates

image

and clicking autoscale

image

clearly visible, the negative performance ins gone as can be seen even in further detail when zooming manually in at the right period

image

Is there a particular reason for these behaviours? a) that the chart does not scale correctly to the limits and b) that the result of the charting is different?

Return file (.RData)
returns.zip

Many thanks for your advice.

@cpsievert
Copy link
Collaborator

This should be fixed in f1900cc. Let us know if you still have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants