I am having trouble getting geom_rug to plot some data into an existing plot. Here's an example plot, where I am comparing some visit day to the magnitude of some measurement.
test <- data.frame(
visit = rep(c(0, 1.5, 3.5, 6.5, 12), 5),
mag = rnorm(n = 25)
)
ggplot(test, aes(x = visit, y = mag)) + geom_point()
Which generates the following plot.
I also have some other data, that I'd like to add just as extra marks on the x axis.
vac <- data.frame(
visit = c(2, 4, 6, 8)
)
For reasons I don't understand, I get no plot at all when I run the following code.
ggplot(test, aes(x = visit, y = mag)) + geom_point() +
geom_rug(data=vac, aes(x = visit))
I presume I have messed up on syntax somehow, but I can't seem to figure out what I am doing wrong here. Any suggestions?
stroke adjusts the thickness of the border for shapes that can take on different colors both inside and outside. It only works for shapes 21-24. What happens if you map an aesthetic to something other than a variable name, like aes(colour = displ < 5) ?
Source: R/geom-rug.r. geom_rug.Rd. A rug plot is a compact visualisation designed to supplement a 2d display with the two 1d marginal distributions. Rug plots display individual cases so are best used with smaller datasets.
A rug plot is a plot of data for a single quantitative variable, displayed as marks along an axis. It is used to visualise the distribution of the data. As such it is analogous to a histogram with zero-width bins, or a one-dimensional scatter plot.
ggplot2 is a robust and a versatile R package, developed by the most well known R developer, Hadley Wickham, for generating aesthetic plots and charts. The ggplot2 implies " Grammar of Graphics " which believes in the principle that a plot can be split into the following basic parts - data refers to a data frame (dataset).
Example: Creating ggplot2 Plot with Two Different Data Frames You have to specify NULL within the ggplot function. Then, you have to specify the different data sets within the geom_point and geom_line functions. my_plot <- ggplot (NULL) + # Printing ggplot2 grphic based on 2 data sets geom_point (data = iris, aes (x = Sepal.
Source: R/geom-rug.r A rug plot is a compact visualisation designed to supplement a 2d display with the two 1d marginal distributions. Rug plots display individual cases so are best used with smaller datasets.
Themes can be used in ggplot2 to change the backgrounds,text colors, legend colors and axis texts. Firstly we save our plot to 'b' and hence create the visualizations by manipulating 'b'. Note that in aesthetics we have written mpg, disp which automatically plots mpg on x axis and disp on y axis.
You should specify inherit.aes = FALSE
in the geom_rug()
line, otherwise it inherits y = mag
from the main ggplot()
call.
ggplot(test, aes(x = visit, y = mag)) +
geom_point() +
geom_rug(data=vac, aes(x = visit), inherit.aes = F)
I would try either this:
ggplot(test, aes(x = visit, y = mag)) + geom_point() +
geom_rug(data=vac, aes(x = visit,y = NULL))
or perhaps a better option this:
ggplot() +
geom_point(data = test,aes(x = visit,y = mag)) +
geom_rug(data=vac, aes(x = visit))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With