如何在同一张图中制作多个变量的箱线图?

How to make boxplots of multiple variable in the the same graph?

我正在寻找如何制作包含多个变量的箱线图。我按照纬度梯度处理物种存在数据。而且我无法将我所有的物种箱线图都放在同一个图形上。我用的是这个脚本,但是我有42种,一个一个做起来会很复杂

Euphau<- read.csv("clip_euphau_past.csv", sep=";", dec=",")

ggplot(Euphau)+
    geom_violin(aes(x=Euphau$Euphausia_crystallorophias, y = Euphau$Latitude))+
    xlab("species") +
    ylab("Latitude")

这是我的数据:

   Latitude Euphausia_crystallorophias Euphausia_frigida Euphausia_longirostris Euphausia_lucens Euphausia_similis
1   -69.050                          0                 0                      0                0                 0
2   -69.052                          0                 0                      1                0                 0
3   -69.000                          0                 0                      1                0                 0
4   -68.999                          0                 1                      0                1                 0
5   -68.987                          1                 1                      0                1                 0
6   -68.980                          0                 1                      1                1                 1
7   -68.966                          0                 0                      0                0                 0
8   -68.956                          1                 0                      0                0                 1
9   -68.946                          0                 0                      0                0                 1
10  -68.945                          1                 0                      0                0                 1
11  -68.900                          0                 0                      0                0                 0

总而言之,我想根据每个物种在纬度上的存在与否制作一个带有箱线图的图表。

您提供的数据不多,但这是您要找的吗?

library(tidyr)
library(dplyr)
pivot_longer(Euphau, -Latitude) %>%
ggplot() +
  geom_violin(aes(x=name, y = Latitude, fill = as.factor(value)))+
  scale_fill_discrete(labels = c("Absent","Present")) + 
    labs(x = "Species", y = "Latitude", fill = "") + 
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))