- R Data Visualization Recipes
- Vitor Bianchi Lanzetta
- 263字
- 2021-07-02 23:33:36
How it works...
Number one step simply stacks geom_boxplot() with geom_dotplot(). Two points are important to reinforce here. First, geom_boxplot() must be called before geom_dotplot(). This order is very important. Second, outliers coming from the boxes have to be erased. Do this by inputting outlier.shape = NA into the function geom_boxplot().
Other than that, all that we have already seen about dot plots may work here too. For example, you could set different colors to work in the dot plot just like we did with the Recipe Using more suitable colors for geom_dotplot. Other geometries could replace dot one to achieve a different vis. Feasible options would be geom_point() and geom_jitter().
Step 2 draws an alternative plot with plotly. It's combining the box geometry with points. After declaring the data, x, and y arguments, such result is achieved by declaring type = 'box' along with boxpoints = 'all'.
In order to reach points properties, call the marker parameter. These properties must be called inside a list object. Recipe tweaked markers' color and alpha (opacity) properties. Points are horizontally jittered; this can be controlled by the jitter argument. The values might range from 0 (no jitter) to 1 (maximum jitter).
Another important argument available is pointpos. Accepted inputs range from -2 to 2. When this argument is set to -2 the points are plotted at the left side of the boxes; a value of 2 will display the points at the right. Pick zero if you want to make points overlay the boxes.