我希望这相当简单。我正在制作 ggplot 箱线图,然后用原始数据覆盖箱线图。但是,我希望这些点不显示为圆形,而是六边形。看起来 ggplot 有一些形状选项,但没有一个是六边形。似乎有一个包(ggstar::geomstar())有六边形(starshape = 6),但我不知道如何将其合并到我的代码中。下面是可重现的示例。
df <- data.frame(variable1 = c(1,3,6,3,5,2,2,4,1))
df
variable1
1 1
2 3
3 6
4 3
5 5
6 2
7 2
8 4
9 1
ggplot(df, aes(x = 0, y = variable1)) +
geom_boxplot(alpha = 0.5, outlier.shape = NA) +
geom_point(position = position_jitter(width = 0.2), color = "red") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(x = NULL)
library(ggplot2)
library(ggstar)
df <- data.frame(variable1 = c(1,3,6,3,5,2,2,4,1))
ggplot(df, aes(x = 0, y = variable1)) +
geom_boxplot(alpha = 0.5, outlier.shape = NA) +
ggstar::geom_star(
position = position_jitter(width = 0.2),
color = "red",
starshape = "hexagon"
)
创建于 2024-04-16,使用 reprex v2.1.0