You can easily add rug on x and y axis thanks to the geom rug function to illustrate the distribution of dots.
Ggplot2 add rug to plot.
By default the rug lines are drawn with a length that corresponds to 3 of the total plot size.
Create elegant data visualisations using the grammar of graphics.
Since the default scale expansion of for continuous variables is 5 at both ends of the scale the rug will not overlap with any data points under the default settings.
As pointed out by csgroen geom rug is the equivalent of rug function.
1 opaque transparency of the rug s lines note that x and y can be used at the same time to draw rugs along both axes.
The following example plot contains three layers.
1992 statistical models in s.
The first layer contains a horizontal rug in red the second layer contains a vertical rug in blue and the third layer shows the underlying points.
Description usage arguments details aesthetics examples.
A string that controls which sides of the plot the rugs appear on.
Rug plots display individual cases so are best used with.
Allowed value is a string containing any of trbl for top right bottom and left.
Library library ggplot2 iris dataset head iris plot ggplot data iris aes x sepal length petal length geom point geom rug col.
I am going to use the mtcars dataset to illustrate.
Because of the way rug is implemented only values of x that fall within the plot region are included.
Add marginal rugs to a scatter plot.
Its not be best dataset for this question.
A rug plot is a compact visualisation designed to supplement a 2d display with the two 1d marginal distributions.
However your rug vector has a different length from x and y so you have to specify pass some arguments into the aes to ge tthe same figure than the one you get in base r plot.
Since the default scale expansion of for continuous variables is 5 at both ends of the scale the rug will not overlap with any data points under the default settings.
There will be a warning if any finite values are omitted but non finite values are omitted silently.
Note you can as well add marginal plots to show these distributions.