violinjitter | R Documentation |
create jitter in a normal-shaped envelope
violinjitter(y, grouping = NULL, maxwidth = 1)
y |
numeric, the response variable (along vertical axis) |
grouping |
character or factor, optional, a grouping factor for |
maxwidth |
positive numeric, the maximum width along the horizontal axis |
a numeric vector of the same length as y
that represents a relative offset to be added to the actual x-coordinates
xdata <- data.frame(id = sample(letters[1:2], 500, TRUE)) xdata$resp[xdata$id == "a"] <- rnorm(n = sum(xdata$id == "a"), mean = -5, sd = 4) xdata$resp[xdata$id == "b"] <- rnorm(n = sum(xdata$id == "b"), mean = 2, sd = 1) plot(0, 0, type = "n", xlim = c(0.5, 2.5), ylim = c(-15, 7)) xdata$xcoord <- as.numeric(xdata$id) points(xdata$xcoord, xdata$resp) plot(0, 0, type = "n", xlim = c(0.5, 2.5), ylim = c(-15, 7)) xdata$xcoord2 <- xdata$xcoord + violinjitter(xdata$resp, grouping = xdata$id, maxwidth = 0.4) points(xdata$xcoord2, xdata$resp, cex = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.