【发布时间】:2022-01-11 04:14:45
【问题描述】:
总共 36 列。
数据示例代码:
df <-
structure(
list(
Bacteroidaceae = c(
0,
0.10944999,
0.104713314,
0.125727668,
0.124136247,
0.005155911,
0.005072778,
0.010231826,
0.010188139
),
Christensenellaceae = c(
0,
0.009910731,
0.010131195,
0.009679938,
0.01147601,
0.010484508,
0.008641566,
0.010017172,
0.010741488
),
treatment = c(
"Original Sample1",
"Original Sample2",
"Original Sample3",
"Original Sample4",
"treatment1_1",
"treatment1_2",
"treatment1_3",
"treatment1_4"
)
),
class = "data.frame",
row.names = c(NA,-8L)
)
我想做的是为数据中的所有列创建图,因此每列将有 2 个图:一个用于处理 1,一个用于原始样本,总共 72 个图
例如:
原始样本类型相同 我尝试使用此代码:
df %>%
tidyr::pivot_longer(!treatment, names_to = "taxa", values_to = "value") %>%
dplyr::filter(str_detect(treatment, "Treatment1")) %>%
for (i in columns(df)){
)
ggplot(aes(x = treatment, y = value, color = taxa),group=treatment) +
geom_point() +
stat_summary(fun.y = mean,
geom = "line", width = 0.5)+geom_jitter(widh=0.25)
theme_bw()}}
但它没有用。 还有其他方法吗?
谢谢
【问题讨论】:
-
重塑为 'long' 后,代码中的
for (i in columns(df)){ )是做什么的。是不是笔误? -
错误:
data必须是一个数据框,或其他可被fortify()强制转换的对象,而不是具有 uneval 类的 S3 对象。您是否不小心将aes()传递给data参数? -
语法不正确,即
for循环位置似乎不正确 -
“for 循环放置似乎不正确”是什么意思?
-
df %>% tidyr::pivot_longer(!treatment, names_to = "taxa", values_to = "value") %>% dplyr::filter(str_detect(treatment, "treatment1")) %>% ggplot(aes(x = treatment, y = value, color = taxa), group = treatment) + geom_point() + stat_summary(fun.y = mean, geom = "line", width = 0.5)+geom_jitter(widh=0.25) theme_bw()此代码似乎有效
标签: r loops ggplot2 geom-point