-
Notifications
You must be signed in to change notification settings - Fork 627
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
Major update to plot_ly()
#628
Conversation
…wnstream plotly stuff
…linetypes mapping; use entire plot schema for better validation
@timelyportfolio it looks like resetting zoom within an R markdown doc is broken on this branch. Could you check out #627 for me and see if it's just v1.13.0 that breaks it? |
This will be really nice. I am working through examples and tests now. The first issue I noticed is in the
and I get I would expect two lines (one raw and a second smoother). Also, the title is lost. I'll work through, but I just want to report, so I don't forget. |
this works
so I'm struggling to understand why the other does not. |
p$x$layoutAttrs <- NULL | ||
p$x$layout <- modify_list(p$x$layout, Reduce(modify_list, layouts)) | ||
|
||
# If type was not specified in plot_ly(), it doesn't create a trace unless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems this explains #628 (comment), but I don't understand the logic. Could you elaborate on this design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I comment out, then both the smoother and raw line are plotted, so this does seem to explain what is happening, but I don't understand why this choice was made. I'm guessing there are use cases where this is beneficial.
@timelyportfolio similar to plot_ly(economics, x = ~date, y = ~pop) %>% add_lines() If no plot_ly(economics, x = ~date, y = ~pop, type = "scatter")
plot_ly(economics, x = ~date, y = ~pop)
No trace type specified. Using the 'scatter' default. Unfortunately, this does introduce some confusing (backwards-incompatible) changes. Take the first example on plot_ly(economics, x = ~date, y = ~uempmed) %>%
add_trace(y = ~fitted(loess(uempmed ~ as.numeric(date)))) But, given this new philosophy (which I think is better and more consistent with grammar of graphics systems), we'd expect that to create one trace. This is now the preferred way to express that plot: plot_ly(economics, x = ~date) %>%
add_lines(y = ~uempmed) %>%
add_lines(y = ~fitted(loess(uempmed ~ as.numeric(date)))) |
nlayouts <- length(p$x$layout) | ||
p$x$layout <- c(p$x$layout, attrs) | ||
} else { | ||
p$x$layoutAttrs[[p$x$cur_data]] <- attrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will overwrite any previous defined layout
. Is this intentional?
data(economics, package = "ggplot2")
# basic time-series plot
p <- plot_ly(economics, x = ~date, y = ~uempmed)
# add a loess smoother
p2 <- add_trace(p, y = ~fitted(loess(uempmed ~ as.numeric(date))))
# add a title
p3 <- layout(p2, title = "Median duration of unemployment (in weeks)")
# change the font
layout(p3, font = list(family = "Courier New, monospace"))
The title
is lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, no, not intentional, I'll fix it, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpsievert, ok that makes much more sense. Then, in this case, I think documentation, discussion, and examples shoul reflect this philosophy/change. Where is the best place to first communicate this? in ?plot_ly
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, working on that as we speak :)
…method() in NAMESPACE
… values + group_by() working; various bug fixes and tests
@jackparmer @timelyportfolio
This is a major update to the
plot_ly()
interface that addresses a number of concerns raised by @hadley / @jcheng5 / others. See the NEWS file for a summary. My goal is to have this on CRAN before I fly out to SF on the 23rd. Here is a list of stuff that should be addressed before submitting:add_polygon()
/add_ribbon()
. BTW, if anyone has ideas for otheradd_*()
functions (to do things that aren't easy/available or slow in ggplot2) I'm all ears!I also think that
color
should be deprecated and split intostroke
/fill
, but that should probably wait for now.