I am interested in generating a series of simple 3d scatterplots which include regression planes without interactions using the scatterplot3d function in R. The following code generates almost what I am after with one problem- in many cases the regression plane extends outside of the bounding box (e.g. in this case, the corner nearest x, y and z =0). I tried changing the axis limits to increase the box size, but this does not alter the axis ranges as specified (which, according to the package documentation is an unfixed bug). Is there a way to either 1) re-draw the box to include the entire plane or 2) shrink the plane to include only the portion within the box?
example data
bugs<-c(335.20,8.68,1.94,3.22,21.79,11.16,1618.00,108.76,250.59,400.81,233.86,15.05,274.62,419.21)
max_dq<-c(0.015,0.001,0.001,0.001,0.002,0.007,0.04,0.001,0.014,0.003,0.002,0.006,0.004,0.013)
since_dist<-c(21,58,5,1,1,19,42,33,22,300,240,79,327,42)
library(scatterplot3d)
3 d plot
reg_plt<-scatterplot3d(max_dq,since_dist,bugs,angle=50)
regression plane
reg_plt$plane3d(lm(bugs~max_dq+since_dist))
Related
I'm currently attempting to construct a 3D confidence region based on the following quadratic form;
confidence region for mean mu
while I have the ellipsoid part figured out; I can't seem to figure out a way to include the major and minor axis. As per the textbook I'm using, the major axis is
length of major axis units in the direction of $e_i$--the ith eigenvector of the estimate of the covariance matrix S. For plotting the ellipsoid, I used the following code that required the rgl package:
plot3d(ellipsoid(mu_1,S_1,(((n-1)*p)/(n-p))*(qf(0.05,df1=p,df2=n-p,lower.tail = FALSE)),segments=100),alpha=0.5,color='blue')
But I believe the function creates its own 3D mesh object within which it produces the ellipse, so I'm having a lot of trouble constructing the 3D eigenvectors on the same 3D plane. In fact, even if I completely abandon the ellipsoid part, I can't seem to find a way to even just draw out the 3D eigenvectors centered at $\bar{x}$. I've loaded packages like plotly and matlib and even tried something as dumb as defining a 3D parametric function of a line that went as follows:
lines <- function(x0,a){ t <- seq(0,1,length=10000) return(matrix(x0+c(a[1]*t,a[2]*t,a[3]*t),nrow=10000,ncol=3,byrow=TRUE)) }
I then went ahead with the plot3d function, to no avail. Any help would be appreciated!
I have this image pixel object, created using Spatstat package in R. The range of x-axis is [0,24], the range of y-axis is [28000, 29500]. When I plot it out in R studio, the graph looks very narrow as below:
I guess it is because the range of x-axis is too small compared to y's. What should I do to make the plot wider?
In the spatstat package, spatial objects are always plotted isometrically. The plot uses the same physical scale for the x and y axes.
Spatial objects in spatstat occupy a specific location and size in two-dimensional space. A pixel image (object of class "im") is associated with a rectangular region at a specific location in two-dimensional space with a specific width and height. If this region is long and thin, then the plotted image will be displayed as long and thin, and will not be rescaled to fit the screen or page.
If you want to stretch a pixel image in spatstat, you need to transform it to another image, which will be defined on a different region of two-dimensional space.
You can do that with the spatstat function affine. In your example, if Z is your original pixel image, you could do
A <- affine(Z, diag(c(60,1)))
The second argument is the transformation matrix, which in this case is just a stretch of the x axis by a factor of 60. (The transformation will stretch the domain of the image, and stretch each individual pixel, by a factor of 60 in the x direction. The number of pixels and the pixel values will be unchanged. No interpolation or other fudging will occur.)
See Chapters 3 and 4 in the spatstat book
I have points list and control points list to draw a Bezier curve.
Please let me know how to calculate the boundary rectangle of the Bezier curve.
var pointsList = [CGPoint(34, 23), ... , CGPoint(23, 85)]
var controlPoints = [CGPoint(45, 34), ..., CGPoint(55, 99)]
Normally not really a hard problem, covered over on http://pomax.github.io/bezierinfo/#boundingbox:
Compute the x and y derivatives, which is super easy to do,
Find all roots (derivative=0) for both derivatives, let's call those the sets r{x} and r{y}, then
Compute the corresponding value sets bezier{x} and bezier{y} for those roots. Then,
Your bounding box has corners defined by the lowest and highest values min/max values in those sets.
In this, only step 2 might be a bit tricky if you're using high order bezier curves. Once your curve consists of more than four points, you can't use symbolic maths to find the roots and it's far easier to just run through the derivative curve and see where the resulting coordinates have a value close enough to zero to treat them as approximate root.
Your graphic looks like it's simply a series of connected cubic Bezier curves, in which case the root finding is easy (the derivatives will be quadratic curves, you learn how to find the roots for those in high school using the quadratic equation), and the box procedure is simply "compute the bounding box for each cubic curve section, and when you're done, the full bounding box simply uses the min/max values across all individual boxes".
My problem is such that I need to reconstruct a circular surface which is observed from an oblique angle so that it shows in the image as an ellipse. From other image parts I can construct the scale in X and Y directions so that I have knowledge of the expected ratio of the axes of the ellipse. The ellipse in question can be defined by points which cover about 1/3 of its circumference, equally distributed where the shorter axis cuts the circumference.
While in principle it's possible to fit an ellipse using these data points (e.g. using Markwardt's ellipse fitting which implements a flavour of the Levenberg-Marquardt technique), it might return wrong parameters as the ratio of axes is not well defined by the data coverage (the excentricity is around 0.3, the ratio of the axes is about 1.05).
I'm looking for an algorithm which allows to give additional constraints when fitting an ellipse or pointers how to tackle that problem.
Neither a search here nor my google-foo returned anything.
I have a set of points like this (that I have clustered using R):
180.06576696, 192.64378568
180.11529253999998, 192.62311824
180.12106092, 191.78020965999997
180.15299478, 192.56909828000002
180.2260287, 192.55455869999997
These points are dispersed around a center point or centroid.
The problem is that the points are very close together and are, thus, difficult to see.
So, how do I move the points apart so that I can distinguish each point more clearly?
Thanks,
s
Maybe I'm overlooking some intricacy here, but...multiply by 10?
EDIT
Assuming the data you listed above are Cartesian (x,y) coordinate pairs, you can visualize them as a scatter plot using Google Charts. I've rounded your data to 3 decimal places, because Google Charts doesn't appear to handle higher precision than that.
I don't know the coordinates for your central point. In the above chart, I'm assuming it is somewhere nearby and not at (0,0). If it is at (0,0), then I imagine it will be difficult to visualize all of the data at once without some kind of "zoom-in" feature, scaling the data, or a very large screen.
slotishtype, without going into code, I think you first need to add in the following tweaking parameters to be used by the visualization code.
Given an x by y display box, fill the entire box, with input parameters [0.0 to 1.0]...
overlap: the allowance for points to be placed on top of each other
completeness: how important is it to display all of your data points
centroid_display: how important is it to see the centroid in the same output
These produce the dependent parameter
scale: the ratio between display distances to numerical distances
You will need code to
calculate the distance(s) to the centroid like you said,
and also the distances between data points, affecting the output based on the chosen input parameters.
I take inspiration from the fundamentals in the GraphViz dot manual. Look at the "Drawing Orientation, Size and Spacing" on p12.