【发布时间】:2020-03-16 08:57:03
【问题描述】:
我正在尝试在base R 的顶部绘制带有数据点的条形图。
我使用base R 是因为不可能以简单的方式在ggplot 中创建纹理填充(例如,参见here,而ggtexture 不允许进行复杂的编辑)。
使用barplot() 函数和points(),我可以做到这一点:
library(tidyverse)
#Sample data
data <- iris %>%
group_by(Species) %>%
summarise(m = mean(Sepal.Length),
se = sd(Sepal.Length)/
sqrt(sum(!is.na(Sepal.Length)))) %>%
ungroup()
chart <- barplot(height=data$m, names=data$Species,
density = c(5, 5, 5),
angle = c(0,45,90),
col = "brown",
width = c(0.1,0.1,0.1),
font.axis = 2,
border = c("black"),
lwd = 2)
points(x = chart,
y = data$m)
但是,我想创建类似于以下内容的内容:
iris %>%
group_by(Species) %>%
summarise(m = mean(Sepal.Length),
se = sd(Sepal.Length)/
sqrt(sum(!is.na(Sepal.Length)))) %>%
ungroup() %>%
ggplot(aes(Species, m,
group = Species,
color = Species,
shape = Species)) +
geom_bar(stat = "identity", fill="white",
color="black") +
geom_jitter(
aes(Species, Sepal.Length),
data = iris)
【问题讨论】:
-
我不想使用ggplot,除非可以使用纹理填充。