what is the right way to display the points on the graph on top of the axes?

Viewed 105

Sometimes there is a need to display points on the graph on top of the axes so that the result looks something like this:

enter image description here

Previously, when I used R, it took a certain amount of alchemy to get the desired result: first the size of the rendering field was set, then the position of the axis, and at the end data points were drawn on top of all this:

f <- rnorm(10, mean=5, sd=1)
plot(x = f, y = c(rep(0, 10)), xlim = c(-1, 11), ylim = c(0, 1),
axes = FALSE, box = FALSE, xaxs = "i", ylab="")
abline(h=0)
axis(side = 1, at = seq(0, 10, 2), pos = 0, tck = -0.02)
points(x = f, y = c(rep(0, 10)), cex=1.0, pch = 21,
col="black", bg="white", lwd = 1)

Now I'm trying to translate my entire workflow to Julia and I want to find some alternative for such visualization. I usually use Plots.jl with GR backend. The trick I used in R does not work in this case: when adding a layer above, it is still cut off by the canvas borders set at the beginning:

c = vcat(1.0, 3.0, 4.0, 6.0, 7.0, 9.0, 12.0, 21.0)
plot(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "", ylims=(0,Inf))
plot!(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "")

Result:

enter image description here

What is the most rational way to get such graphics with Julia?

1 Answers

You should be able to plot on the x-axis by using framestyle=:origin or framestyle=:zerolines

scatter(c, zeros(length(c)), 
        markersize=5, markershape=:circle, 
        color = :red, label="", framestyle=:zerolines)

enter image description here

and if you want to show just the x-axis

scatter(c, zeros(length(c)), markersize=5, 
        markershape=:circle, color = :red, legend=false, 
        framestyle=:origin, yaxis=false, grid=false, aspect_ratio=1.0)

enter image description here

Related