Skip to content

Added support for ggplot2's facets. #44

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

Merged
merged 13 commits into from
Jun 25, 2014
Merged

Added support for ggplot2's facets. #44

merged 13 commits into from
Jun 25, 2014

Conversation

xsaintmleux
Copy link

Please review...

@tdhock
Copy link
Contributor

tdhock commented May 28, 2014

Hello Xavier, it looks like you have written some nice code.

However I put together a test case in tests/testthat/test-facets.R and it there seem to be a couple of problems:

  • For the barley data viz, I was expecting gg2list to output 12 traces, (2 values of year/color, 6 values of site/facet). Instead there are 18 traces.
  • some traces (1 and 7) do not have xaxis and yaxis properties.
  • some traces have no data.

any ideas?

@tdhock
Copy link
Contributor

tdhock commented May 28, 2014

@xsaintmleux
Copy link
Author

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a moment.
The traces with no data are normal: depending on the data and how facets
are defined, some panels may have no data and in some cases plotly doesn't
draw the background. There is one empty trace per panel just to make sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly
https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44447426
.

@tdhock
Copy link
Contributor

tdhock commented May 28, 2014

Can you clarify what you mean by "some panels may have no data?"

In ggplot2, there is no such thing as a facet/panel with no data. The only
exception is http://docs.ggplot2.org/0.9.3.1/geom_blank.html

In the example I gave, all 6 panels do have data, so adding additional
traces with no data just makes for a bigger, more inefficient JSON file to
upload, right?

On Wed, May 28, 2014 at 3:19 PM, xsaintmleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a moment.
The traces with no data are normal: depending on the data and how facets
are defined, some panels may have no data and in some cases plotly doesn't
draw the background. There is one empty trace per panel just to make sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44452268
.

@xsaintmleux
Copy link
Author

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which is
normal (unless you can suggest something better.) Traces 1 and 7 use the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected] wrote:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a moment.
The traces with no data are normal: depending on the data and how facets
are defined, some panels may have no data and in some cases plotly doesn't
draw the background. There is one empty trace per panel just to make sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly
https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44447426
.

@xsaintmleux
Copy link
Author

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected] wrote:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which is
normal (unless you can suggest something better.) Traces 1 and 7 use the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a moment.
The traces with no data are normal: depending on the data and how facets
are defined, some panels may have no data and in some cases plotly doesn't
draw the background. There is one empty trace per panel just to make sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly
https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44447426
.

@xsaintmleux
Copy link
Author

OK, I see what it is: I just didn't add support for factors on the x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected] wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which is
normal (unless you can suggest something better.) Traces 1 and 7 use the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a moment.
The traces with no data are normal: depending on the data and how facets
are defined, some panels may have no data and in some cases plotly doesn't
draw the background. There is one empty trace per panel just to make sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly
https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44447426
.

@tdhock
Copy link
Contributor

tdhock commented May 28, 2014

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux [email protected]:

OK, I see what it is: I just didn't add support for factors on the x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which is
normal (unless you can suggest something better.) Traces 1 and 7 use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a
moment.
The traces with no data are normal: depending on the data and how
facets
are defined, some panels may have no data and in some cases plotly
doesn't
draw the background. There is one empty trace per panel just to make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44455838
.

@tdhock
Copy link
Contributor

tdhock commented May 28, 2014

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected] wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux [email protected]:

OK, I see what it is: I just didn't add support for factors on the x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which is
normal (unless you can suggest something better.) Traces 1 and 7 use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a
moment.
The traces with no data are normal: depending on the data and how
facets
are defined, some panels may have no data and in some cases plotly
doesn't
draw the background. There is one empty trace per panel just to make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44455838
.

@xsaintmleux
Copy link
Author

Not displaying the background could make sense, but I was trying to display
something that is as close as possible to what ggplot2 displays and it
shows the background everywhere by default. There might be a ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is displayed
and sometimes it isn't, so it would not be possible right now to never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected] wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux [email protected]:

OK, I see what it is: I just didn't add support for factors on the x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which
is
normal (unless you can suggest something better.) Traces 1 and 7 use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a
moment.
The traces with no data are normal: depending on the data and how
facets
are defined, some panels may have no data and in some cases plotly
doesn't
draw the background. There is one empty trace per panel just to
make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44456921
.

@xsaintmleux
Copy link
Author

It's getting better:
http://ec2-54-227-170-120.compute-1.amazonaws.com/~xsaintmleux/28

On Wed, May 28, 2014 at 4:27 PM, Xavier Saint-Mleux [email protected] wrote:

Not displaying the background could make sense, but I was trying to
display something that is as close as possible to what ggplot2 displays and
it shows the background everywhere by default. There might be a ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is displayed
and sometimes it isn't, so it would not be possible right now to never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected] wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey
background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux [email protected]:

OK, I see what it is: I just didn't add support for factors on the x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which
is
normal (unless you can suggest something better.) Traces 1 and 7
use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux [email protected]:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a
moment.
The traces with no data are normal: depending on the data and how
facets
are defined, some panels may have no data and in some cases plotly
doesn't
draw the background. There is one empty trace per panel just to
make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHubhttps://github.com//pull/44#issuecomment-44456921
.

@xsaintmleux
Copy link
Author

Hey Toby and Marianne,

I'm digging into ggplot_build because it sorts the data by panel, which
means that at the beginning of layer2traces the line:

    g$data[[a]] <- data.vec

adds an unsorted column to a sorted data.frame. I'd like to use merge to
add columns so that they are in the right order, but it seems that
ggplot_build discards some of the information needed to do that (for
panels.) Do you have any ideas?.. I'd like not to have to write my own
ggplot_build.

Thanks,

Xavier

On Wed, May 28, 2014 at 5:56 PM, Xavier Saint-Mleux [email protected] wrote:

It's getting better:
http://ec2-54-227-170-120.compute-1.amazonaws.com/~xsaintmleux/28

On Wed, May 28, 2014 at 4:27 PM, Xavier Saint-Mleux [email protected]
wrote:

Not displaying the background could make sense, but I was trying to
display something that is as close as possible to what ggplot2 displays and
it shows the background everywhere by default. There might be a ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is displayed
and sometimes it isn't, so it would not be possible right now to never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to
look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected]
wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey
background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux [email protected]:

OK, I see what it is: I just didn't add support for factors on the
x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux [email protected]:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces, which
is
normal (unless you can suggest something better.) Traces 1 and 7
use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in a
moment.
The traces with no data are normal: depending on the data and how
facets
are defined, some panels may have no data and in some cases
plotly
doesn't
draw the background. There is one empty trace per panel just to
make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHub
#44 (comment).

@tdhock
Copy link
Contributor

tdhock commented May 29, 2014

one idea is to add some aesthetics before building the ggplot -- I dod that
to make sure the legend names are kept in the built data.frame so we can
use them in the plotly legend

https://github.com/ropensci/plotly/blob/master/R/ggplotly.R#L226

On Thu, May 29, 2014 at 2:59 PM, xsaintmleux [email protected]
wrote:

Hey Toby and Marianne,

I'm digging into ggplot_build because it sorts the data by panel, which
means that at the beginning of layer2traces the line:

g$data[[a]] <- data.vec

adds an unsorted column to a sorted data.frame. I'd like to use merge to
add columns so that they are in the right order, but it seems that
ggplot_build discards some of the information needed to do that (for
panels.) Do you have any ideas?.. I'd like not to have to write my own
ggplot_build.

Thanks,

Xavier

On Wed, May 28, 2014 at 5:56 PM, Xavier Saint-Mleux [email protected]
wrote:

It's getting better:
http://ec2-54-227-170-120.compute-1.amazonaws.com/~xsaintmleux/28

On Wed, May 28, 2014 at 4:27 PM, Xavier Saint-Mleux [email protected]
wrote:

Not displaying the background could make sense, but I was trying to
display something that is as close as possible to what ggplot2 displays
and
it shows the background everywhere by default. There might be a ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is
displayed
and sometimes it isn't, so it would not be possible right now to never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so
that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to
look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected]
wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey
background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux <
[email protected]>wrote:

OK, I see what it is: I just didn't add support for factors on the
x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux [email protected]

wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces,
which
is
normal (unless you can suggest something better.) Traces 1 and 7
use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in
a
moment.
The traces with no data are normal: depending on the data and
how
facets
are defined, some panels may have no data and in some cases
plotly
doesn't
draw the background. There is one empty trace per panel just to
make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHub
#44 (comment).


Reply to this email directly or view it on GitHub
#44 (comment).

@tdhock
Copy link
Contributor

tdhock commented May 29, 2014

by the way the merge function can be slow for large data, so maybe it is a
good idea to just use standard vector operations?

On Thu, May 29, 2014 at 3:03 PM, Toby Hocking [email protected] wrote:

one idea is to add some aesthetics before building the ggplot -- I dod
that to make sure the legend names are kept in the built data.frame so we
can use them in the plotly legend

https://github.com/ropensci/plotly/blob/master/R/ggplotly.R#L226

On Thu, May 29, 2014 at 2:59 PM, xsaintmleux [email protected]
wrote:

Hey Toby and Marianne,

I'm digging into ggplot_build because it sorts the data by panel, which
means that at the beginning of layer2traces the line:

g$data[[a]] <- data.vec

adds an unsorted column to a sorted data.frame. I'd like to use merge to
add columns so that they are in the right order, but it seems that
ggplot_build discards some of the information needed to do that (for
panels.) Do you have any ideas?.. I'd like not to have to write my own
ggplot_build.

Thanks,

Xavier

On Wed, May 28, 2014 at 5:56 PM, Xavier Saint-Mleux [email protected]
wrote:

It's getting better:
http://ec2-54-227-170-120.compute-1.amazonaws.com/~xsaintmleux/28

On Wed, May 28, 2014 at 4:27 PM, Xavier Saint-Mleux [email protected]
wrote:

Not displaying the background could make sense, but I was trying to
display something that is as close as possible to what ggplot2
displays and
it shows the background everywhere by default. There might be a
ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is
displayed
and sometimes it isn't, so it would not be possible right now to never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so
that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying to
look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected]
wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey
background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux <
[email protected]>wrote:

OK, I see what it is: I just didn't add support for factors on the
x/y
axes. I'll do that. For now, it works as long as x/y are numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux <
[email protected]>
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces,
which
is
normal (unless you can suggest something better.) Traces 1 and
7
use
the
default axes (x and y.) Do you think I should make it explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that in
a
moment.
The traces with no data are normal: depending on the data and
how
facets
are defined, some panels may have no data and in some cases
plotly
doesn't
draw the background. There is one empty trace per panel just
to
make
sure
the background shows. Do you know of a better way to do this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>
.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHub
#44 (comment).


Reply to this email directly or view it on GitHub
#44 (comment).

@xsaintmleux
Copy link
Author

I'd have to use match to get the index I need for vector operations and
match is what merge uses internally. I'll use Rprof and read the
merge/match code. At best, it'll be O(n*log(n)) on the number of rows and
merge is always more readable.

BTW, the way you save/use the aesthetics is what needs to be fixed to
support facets; it only works if ggplot_build doesn't reorder the data.

On Thu, May 29, 2014 at 3:04 PM, Toby Dylan Hocking <
[email protected]> wrote:

by the way the merge function can be slow for large data, so maybe it is a
good idea to just use standard vector operations?

On Thu, May 29, 2014 at 3:03 PM, Toby Hocking [email protected] wrote:

one idea is to add some aesthetics before building the ggplot -- I dod
that to make sure the legend names are kept in the built data.frame so
we
can use them in the plotly legend

https://github.com/ropensci/plotly/blob/master/R/ggplotly.R#L226

On Thu, May 29, 2014 at 2:59 PM, xsaintmleux [email protected]
wrote:

Hey Toby and Marianne,

I'm digging into ggplot_build because it sorts the data by panel, which
means that at the beginning of layer2traces the line:

g$data[[a]] <- data.vec

adds an unsorted column to a sorted data.frame. I'd like to use merge
to
add columns so that they are in the right order, but it seems that
ggplot_build discards some of the information needed to do that (for
panels.) Do you have any ideas?.. I'd like not to have to write my own
ggplot_build.

Thanks,

Xavier

On Wed, May 28, 2014 at 5:56 PM, Xavier Saint-Mleux [email protected]
wrote:

It's getting better:
http://ec2-54-227-170-120.compute-1.amazonaws.com/~xsaintmleux/28

On Wed, May 28, 2014 at 4:27 PM, Xavier Saint-Mleux [email protected]
wrote:

Not displaying the background could make sense, but I was trying to
display something that is as close as possible to what ggplot2
displays and
it shows the background everywhere by default. There might be a
ggplot2
option for that but I don't know it. There is also something strange
happening with panels with no traces: sometimes the background is
displayed
and sometimes it isn't, so it would not be possible right now to
never
display the background if there is no data. This is on my list of
questions for Alex and I'm also starting to dig into the js code so
that I
can understand what is happening.

On Wed, May 28, 2014 at 4:01 PM, Toby Dylan Hocking <
[email protected]> wrote:

for me the plot would be easier to read if we do not draw the grey
background when there is no data.

otherwise I find myself squinting at the blank grey panels trying
to
look
for data points.

On Wed, May 28, 2014 at 3:58 PM, Toby Hocking [email protected]
wrote:

that is very nice xav. good job!

you are right. it is possible to have empty facets/panels with
facet_grid.
I forgot about that.

so what is the difference between a panel with no data (grey
background)
and a panel with no background?

On Wed, May 28, 2014 at 3:51 PM, xsaintmleux <
[email protected]>wrote:

OK, I see what it is: I just didn't add support for factors on
the
x/y
axes. I'll do that. For now, it works as long as x/y are
numeric.

On Wed, May 28, 2014 at 3:42 PM, Xavier Saint-Mleux <
[email protected]>
wrote:

This is what I mean:

https://plot.ly/~xsaintmleux/211

On Wed, May 28, 2014 at 3:40 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Ouch! this is a good test... I still have some work to do!

So, the 18 traces are because of the six extra empty traces,
which
is
normal (unless you can suggest something better.) Traces 1
and
7
use
the
default axes (x and y.) Do you think I should make it
explicit?

On Wed, May 28, 2014 at 3:18 PM, Xavier Saint-Mleux <
[email protected]>wrote:

Hi Toby,

I saw your test code but I haven't run it yet; I'll do that
in
a
moment.
The traces with no data are normal: depending on the data
and
how
facets
are defined, some panels may have no data and in some cases
plotly
doesn't
draw the background. There is one empty trace per panel just
to
make
sure
the background shows. Do you know of a better way to do
this?

Chers,

Xavier

On Wed, May 28, 2014 at 2:37 PM, Toby Dylan Hocking <
[email protected]> wrote:

also it results in this plotly

https://plot.ly/~tdhock/177/1932-1932-1932-1932-1932-1932-1931-1931-1931-1931-1931-1931/


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44447426>

.


Reply to this email directly or view it on GitHub<
https://github.com/ropensci/plotly/pull/44#issuecomment-44455838>
.


Reply to this email directly or view it on GitHub
#44 (comment).


Reply to this email directly or view it on GitHub
#44 (comment).


Reply to this email directly or view it on GitHub
#44 (comment).

@tdhock
Copy link
Contributor

tdhock commented Jun 2, 2014

by the way my GSOC student Carson Sievert is working on converting ggplot2 facets to animint panels, and he put together this viz to better understand the internal structure of the ggplot object

https://cpsievert.shinyapps.io/ggtree/

@xsaintmleux
Copy link
Author

I'll take a look at that, thanks!

I misunderstood you the other day: now I see what you meant when talking
about adding aesthetics. There might be easier ways to support factors and
dates though, I'm still juggling with a few ideas.

On Mon, Jun 2, 2014 at 8:56 AM, Toby Dylan Hocking <[email protected]

wrote:

by the way my GSOC student Carson Sievert is working on converting ggplot2
facets to animint panels, and he put together this viz to better understand
the internal structure of the ggplot object

https://cpsievert.shinyapps.io/ggtree/


Reply to this email directly or view it on GitHub
#44 (comment).

@xsaintmleux
Copy link
Author

@mkcor which line?

@mkcor
Copy link
Contributor

mkcor commented Jun 25, 2014

+1

xsaintmleux pushed a commit that referenced this pull request Jun 25, 2014
Added support for ggplot2's facets.
@xsaintmleux xsaintmleux merged commit bf54b30 into master Jun 25, 2014
@mkcor mkcor deleted the facets1 branch August 19, 2014 19:28
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

Successfully merging this pull request may close these issues.

3 participants