ggplot2::ggeom_rug
In this document, I will introduce the geom_rug()
function and show what it’s for.
#load ggridges
library(ggplot2)
#load dataset
data("cars")
geom_rug()
is part of the ggplot2 package, which is part of tidyverse.
We use
geom_rug()
to create tick marks on the edge of the axis. This helps in aiding the design for any graphs that are presented. Below we can see geom_rug being used without a scatterplot graph. As we can see below, usinggeom_rug
by itself will only display the tick marks for each point of the (x,y) coordinates but doesn’t necessarily show which points it’s identifying. It’s useful when combined with a graph that has data points, otherwise it doesn’t provide much information to do any analysis by itself.
ggplot(cars, aes(x = speed, y = dist))+
geom_rug()
When combined with a scatterplot, it gives us a better visualization of each point on the graph rather than guessing each point’s (x,y) coordinates.
ggplot(cars, aes(x = speed, y = dist))+
geom_point() +
geom_rug()
We are also able to customize our
geom_rug
, we can change where the tick mark is displayed. What color the tick marks are and even bring out the tick marks outside the grid in case an individual would prefer that the tick marks doesn’t interfere with their data inside.
ggplot(cars, aes(x=speed, y=dist)) +
geom_point() +
geom_rug(sides = "trbl", color = "skyblue")
ggplot(cars, aes(x=speed, y=dist)) +
geom_point() +
geom_rug(outside = T, color = "skyblue", size = 1.5) +
geom_rug(sides = "tr", outside = T, color = "gold", size = 1.5) +
coord_cartesian(clip = "off")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
data("iris")
ggplot(iris, aes(x = Petal.Length,
fill = Species)) +
geom_bar() +
geom_rug()
We can try to combine it with other graphs but it doesn’t fit nicely as we would hope compared to
geom_point
. So it seems likegeom_rug
is a tool mainly for scatterplot graphs. If we were to implement it with bar graphs, there are better tools we can use to draw tick marks on bar graphs if we need it.
I believe this function is quite helpful. I don’t think i’ll use this function as much but knowing we have the capability to create tick marks for our scatterplot would be useful, especially if the plot contains a lot of data points. The only downfall regarding this type of plot is only useful with scatterplots, as far as i know. We can use it with
geom_line
andgeom_bar
but it becomes very messy and confusing, so it wouldn’t really make sense to use it with either of those graphs.