What's Julia's Plots.jl's equivalent of R's `abline`? - julia

R's abline draws a straight line parameterised by y = ax+b on the x-y 2D coordinate plan.
What's Julia's equivalent of that in Plots.jl?

There is Plots.abline! which draws a straight line in the form of ax+b respecting axis limits of the plot. So it will not actually go to infinity but does not require you to know what the axis limits are beforehand.
plot(x->((x^2+3x+2)/(x-2)), 6, 30, xlim=(6,30), size=(300,300))
# draw oblique asymptote to the above function (y=x+5)
Plots.abline!(1, 5, line=:dash)
You can also plot a straight line using only two points that are on the line. This should also respect the axis limits.
plot!([x1, x2], [y1, y2], seriestype = :straightline, kwargs...)

Related

Is there a way to plot the ''true'' coordinates on the x and y axis using lidR package

I want to plot a pointcloud in R using the lidR package. When I plot a pointcloud it automatically uses x and y axis values where the coordinates have been normalized starting from 0, I want to see the actual coordinates from the attribute of the las dataset.
LASfile <- system.file("extdata", "MixedConifer.laz", package="lidR")
las <- readLAS(LASfile)
plot(las, axis = TRUE)
This is documented in plot
clear_artifacts logical. It is a known and documented issue that the 3D visualisation with rgl displays artifacts. The points look aligned and/or regularly spaced in some view angles. This is because rgl computes with single precision float. To fix that the point cloud is shifted to (0,0) to reduce the number of digits needed to represent its coordinates. The drawback is that the point cloud is not plotted at its actual coordinates.
plot(las, axis = TRUE, clear_artifacts = FALSE)
This is also somehow documented in chapter 2.3 of the book.

Trying to setting a range for abline in R

When I use the abline in R ,
plot(NULL,xlim=c(0,50),ylim=c(-30,0))
abline(h=-15,col='black')
how do I set the range of x axis to a certain range?
(like a horizontal line at y=-15,but end with x =50) (not using xlim)
You can use the lines() function, taking an x and y coordinate of start/end point. This example has starting point (0|-15) and end point (50|-15):
lines(x=c(0,50), y=c(-15,-15))

EZPLOT tangent curve gets cut off

I'm trying to draw a tangent plot using the EZPLOT function.
For some reason the tangent gets cut off on the y axis after a certain value.
Is there a way of setting ezplot's y axis range of drawing?

Plotting ellipsoids / oblate spheroids in rgl

I have been using rgl to plot spheres, but now I need to plot ellipsoids.
The package includes ellipse3d; however, this seems to be for fitting ellipsoids to data, using matrices and stuff I'm not very good at.
What I want is a simple way to plot ellipsoids, in a similar way to spheres, using the centre coordinates and the scales in each direction. Can anyone help me out?
If you don't need the ellipse rotated around the axes, then you can just use a diagonal matrix for x (this plots a sphere, and defines the virtual "axes" along the x, y, z axes) and use the centre and scale parameters to shift the location and change the proportions.
plot3d(ellipse3d(diag(3),centre=c(1,2,4),scale=c(1,2,5)))
There's one in my cda package,
library(cda)
library(rgl)
## single ellipsoid
plot3d(rgl.ellipsoid(a=2,b=1,c=5))
## multiple ellipsoids, translated and rotated
cl <- helix(0.5, 1, 36, delta=pi/6, n.smooth=1e3)
sizes <- equal_sizes(0.04,0.02,0.02,NROW(cl$positions))
rgl.ellipsoids(cl$positions, sizes, cl$angles, col="gold")

GraphPad Mann Whitney scatter plot in R

I try to make a plot similar to the top three plot of this:
I found a partial answer here, however I am unsure how to add the p-values in the scatter-plot.
Any tips?
You've already got a partial answer. If you just want to know how to put p-values on then use text. (looking at graph C).
text(x = 1.5, y = 73, 'p = 0.03')
If you want the p-values and the lines underneath, assuming you also want those caps on the lines, use arrows instead of segments.
arrows(1, 70, 2, length = 2, angle = 90, code = 3)
If you're sticking with solving this in base R that's a great learning exercise and can give you full control over your plot. However, if you just want to get it done I'd suggest the beeswarm package (you're making beeswarm plots).
As an aside, this prompted me to investigate why you get those upward curving lines in beeswarm plots. It's a consequence of the typical algorithm. The line curves upward because the positions are calculated through increasing y-values. If the next y-value is so close that the points would overlap in the y-axis it's plotted at an angle off the x position. Many points close together on Y results in upward curving lines until you get far enough along Y to go back to X. Smaller points should alleviate that. Also, the beeswarm package in R has several optional algorithms that avoid that as well.

Resources