我是R包EnvStats的创建者.
有一个我经常使用的函数叫做stripChart.我刚刚开始学习ggplot2,过去几天一直在研究哈德利的书,温斯顿的书,StackOverflow和其他资源,试图创造一个geom近似于它的东西stripChart.我无法弄清楚如何geom计算汇总统计数据和测试结果,然后将它们放在x轴刻度线下方以及绘图顶部(绘图区域外).以下是使用内置数据集的简单示例mtcars:
library(EnvStats)
stripChart(mpg ~ cyl, data = mtcars, col = 1:3,
xlab = "Number of Cylinders", ylab = "Miles per Gallon", p.value = TRUE)
Run Code Online (Sandbox Code Playgroud)
以下是尝试重现stripChart的大部分功能的geom的早期草稿:
geom_stripchart <-
function(..., x.nudge = 0.3,
jitter.params = list(width = 0.3, height = 0),
mean.params = list(size = 2, position = position_nudge(x = x.nudge)),
errorbar.params = list(size = 1, width = 0.1,
position = position_nudge(x = x.nudge)),
n.text = TRUE, …Run Code Online (Sandbox Code Playgroud)