This question came to me when I read How convert list of numbers to list of points on x-axis?
@Mr.W suggested Interlacing a single number into a long list for the question. @Artes provides a very fast way to generate the coordinates for plotting. All these remind me a widely used graph in R
, which is called rug representation. I find Mathematica seems do not provide an equivalent command.
Following are three rug plots generated in R
. The basic idea of rug is that project the data points onto an axes and represent it as thin lines beside the axes. Usually, the points will be jittered a bit off the position to avoid tiles. Using function like Line
or ListLinePlot
can somehow implement this function, but I do not know what is the fastest way to implement this function. Is Line
with @Artes's solution the best choice?
More info about rug representation
Sorry for replying messages so late! Here is more information about rug representation.
rug representation is not a density plot, it projects each point to the axes with a thin line. Thus, there is not bandwidth in rug representation. For dataset with tiles, the lines will be overlapped. There are two methods to get rid of this problem. One is using opacity to show how many lines are overlap; the other is jitter the coordinate a bit off the original position, then all lines are visible. The second option are used more widely. The jitter of coordinate can be set to RandomReal[{Min[x], Max[x]},Length@x]/50
.
For the sample data, two well-known datasets from R
: mtcars and iris can be used. The sample figure are plot of wt
vs mpg
in mtcars
.
The start codes for the figure can be
mtcars = Import["mtcars.csv"];
x = Drop[mtcars[[All, 7]], 1];
y = Drop[mtcars[[All, 2]], 1];
ListPlot[Thread[List[x, y]]]
Ticks
/FrameTicks
appropriately. I notice that the thickness of each "fiber" in the rug depends on how many points have the same abscissa or ordinate;Tally[]
should be useful here in conjunction withThickness[]
orAbsoluteThickness[]
. $\endgroup$iris
dataset is built-in:ExampleData[{"Statistics", "FisherIris"}]
. $\endgroup$