0

I am using the scatterD3 library (which I find very eye-pleasing) in R for creating a scatter plot.

I want to keep my axes fixed, but when I do so my points are not in the centre anymore. It is a minor issue I can live with, but, I could easily fix the problem if the axes value labels could be edited.

My javascript and htmlwidgets knowledge is limited, hence my question: Is there a way to edit the axes value labels?

library(scatterD3)
xvar=cos(seq(0,2*pi,length.out=200))
yvar=sin(seq(0,2*pi,length.out=200))


scatterD3(x=xvar,y=yvar,fixed=TRUE)

move<-c(1,3)
scatterD3(x=xvar+move[1],y=yvar+move[2],fixed=TRUE)
# If I try to fix the axes' limits
scatterD3(x=xvar+move[1],y=yvar+move[2],xlim=c(-0.2,2.2),ylim=c(1.8,4.2),fixed=TRUE)

# I can put it in the origin and change the tooltip but the axes would be wrong
tooltips<-paste("xvar: ",xvar+move[1],"<br />","yvar: ",yvar+move[2])
scatterD3(x=xvar,y=yvar,fixed=TRUE,tooltip_text=tooltips)

Edit 2016-11-24

The current development version works properly when fixing xlim and ylim (3rd example). I include a rudimentary piece of r code that centres the scatterplot (changed the circle to an ellipse so the problem is more apparent). Also, I opened an issue in github following Juba's suggestion.

xvar=cos(seq(0,2*pi,length.out=200))
yvar=2*sin(seq(0,2*pi,length.out=200))
move<-c(1,3)
xvar=xvar+move[1]
yvar=yvar+move[2]
scatterD3(x=xvar,y=yvar,fixed=TRUE)

# margin included so the points are not just at the border
margin=0.02

#calculate xlim and ylim
xmin=min(xvar)
xmax=max(xvar)
xd=xmax-xmin
xmin=xmin-xd*margin
xmax=xmax-xd*margin

ymin=min(yvar)
ymax=max(yvar)
yd=ymax-ymin
ymin=ymin-yd*margin
ymax=ymax+yd*margin

if(xd>yd){
    ymin=ymin-(xd-yd)/2
    ymax=ymax+(xd-yd)/2
}else{
    xmin=xmin-(yd-xd)/2
    xmax=xmax+(yd-xd)/2
}

scatterD3(x=xvar,y=yvar,
          xlim=c(xmin,xmax),
          ylim=c(ymin,ymax),
          fixed=TRUE)

Edit 2016-12-01

The issue is happily fixed in the current development version under Linux and Windows (I am pretty sure it works for Mac but I have not tested it). I do not know if I should flag for closure as suggested here or delete the question as suggested here.

Community
  • 1
  • 1
Jon Nagra
  • 1,538
  • 1
  • 16
  • 36
  • Package author here. You make me realize there may be a wrong behavior here. Could you fill an issue in the project's Github ? https://github.com/juba/scatterD3/issues – juba Nov 24 '16 at 09:55
  • 1
    I have run the example with the development version of the package in both my linux and windows OS, and currently, the third example seems to met my purposes. I have opened the issue because the xlim and ylim should be automatically set (it has been also a great opportunity to try github). I will edit my question here adding the code included in the issue. – Jon Nagra Nov 24 '16 at 20:41

0 Answers0