我正在寻找如何制作一个多变量的boxplot。我的工作是按照纬度梯度的物种存在数据。我不能让我所有的物种在同一个图形上绘制boxplot。我使用了这个脚本,但我有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
总结一下,我想根据每个物种在纬度上的存在与否 来制作一个带有boxplot的图表。
你没有提供太多数据,但这是你要找的吗?
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))