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.