我有一个类似这样的数据集:
我希望能够比较物种A的值和同一研究中其他物种的值。
这是目前我拥有的图表:
df <- data.frame(Species = c("Sp A", "Other sp", "Other sp", "Other sp",
"Sp A", "Other sp", "Other sp"),
Study = c("A", "A", "A", "A",
"B", "B", "B"),
Value = c(1, 3, 4, 5, 3, 6, 7))
Looks like this :
> df
Species Study Value
1 Sp A A 1
2 Other sp A 3
3 Other sp A 4
4 Other sp A 5
5 Sp A B 3
6 Other sp B 6
7 Other sp B 7
我希望能够比较物种A的值和同一研究中其他物种的值。
这是目前我拥有的图表:
ggplot(df, aes(y = Value, x = Species)) +
geom_point(shape = 1) +
geom_line(aes(group = Study), color = "gray50") +
theme_bw()
我不想要竖线。相反,我想要5条线,其中3条从下面的“Sp A”点开始,朝着同一研究(A)中对应的“其他sp”点,另外2条从上面的“Sp A”开始,朝着同一研究(B)中的另外2个点。
slice
行。这是不必要的,并且会导致相同行的乘法。在基本 R 中使用merge(df[df$Species == "Sp A",], df[df$Species != "Sp A",], by = "Study", all = TRUE)
可以得到相同的结果。 - Gilles San Martinvalue=6
和value=7
时的情况。 - Brian