Skip to content

size argument doesn't always map correctly to marker.size #1479

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
cpsievert opened this issue Mar 6, 2019 · 7 comments
Closed

size argument doesn't always map correctly to marker.size #1479

cpsievert opened this issue Mar 6, 2019 · 7 comments
Labels

Comments

@cpsievert
Copy link
Collaborator

cpsievert commented Mar 6, 2019

A minimal example, this should render 10 points, but it only renders 1 currently

plot_ly(x = 1:10, y = 1:10, size = I(30))

screen shot 2019-03-06 at 4 53 39 pm

Note the current CRAN version (4.8.0) also has this problem

@mmgledhill
Copy link

mmgledhill commented Mar 7, 2019

Another example where marker size is incorrect. Confirmed Issue exists in current CRAN version and development version in github.

Suspect it occurs when data is not grouped together (ordered by color variable) since it looks ok when the data is grouped by color variable

library(plotly)
library(data.table)
#plotly not sizing markers correctly
myiris<-data.table(iris)
#make one species distinctly different
#will use as sizing
myiris[Species=="virginica", Sepal.Width:=Sepal.Width/4]
sizeref <- 2.0 * max(iris$Sepal.Width) / (50**2)
#this version looks like it might be ok?
pg<-plot_ly(myiris,
                          x=1:nrow(iris),
                          y=~Sepal.Length,
                           type="scatter",
                           mode='markers',
                           text=~Sepal.Width,
                           color=~Species,
                           marker = list(size = ~Sepal.Width, opacity = 0.5, sizemode = 'area', sizeref = sizeref))
pg

size_ok

#break by mixing Species, expect all virginica to be about 1/4 of others
myiris<-myiris[order(Sepal.Length)]
pg<-plot_ly(myiris,
x=1:nrow(iris),
y=~Sepal.Length,
type="scatter",
mode='markers',
text=~Sepal.Width,
color=~Species,
marker = list(size = ~Sepal.Width, opacity = 0.5, sizemode = 'area', sizeref = sizeref))

pg
size_incorrect

@cpsievert
Copy link
Collaborator Author

I think this is due to a different bug that you can avoid by using size and sizes instead of using the plotly.js marker API directly, like:

plot_ly(myiris,
        x=1:nrow(iris),
        y=~Sepal.Length,
        type="scatter",
        mode='markers',
        text=~Sepal.Width,
        color=~Species,
        size = ~Sepal.Width, sizes = c(10, 100) * 15)

@mmgledhill
Copy link

Thank you for the quick reply.

Your solution looks like it corrects the sizing issue but now there are missing points (where size is expected to be the same as other visible points) when I apply it to real-world data. Probably related to issue you highlighted above?

If I use the marker api, I can see all points but need to sort data ahead of time to correct the sizing issues.

@cpsievert
Copy link
Collaborator Author

Yea, try using the approach I suggested on your real data with devtools::install_github("ropensci/plotly#1480") installed

@mmgledhill
Copy link

The development version of github definitely fixes the issue. Do you know when it will be released to CRAN? I'm trying to bundle with packrat when I deploy to Rconnect but it is still using the global CRAN version that is already installed even though the github version is in my packrat.lock file. Any advise?

@cpsievert
Copy link
Collaborator Author

Hopefully this week

@mmgledhill
Copy link

Saw that it was just deployed. You are awesome!

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

No branches or pull requests

2 participants