[英]How to make boxplots of multiple variable in the the same graph?
I am looking for how to make a boxplot with multiple variables.我正在寻找如何制作具有多个变量的箱线图。 I work on species presence data following a latitudinal gradient.
我根据纬度梯度处理物种存在数据。 And I can't get all my species boxplot on the same graphic.
而且我无法将我所有的物种箱线图都放在同一个图形上。 I used this script, but I have 42 species it will be complicated to do it one by one.
我用了这个脚本,但是我有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")
Here is my data:这是我的数据:
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
To summarize, I want to make a graph with a boxplot for each species according to their presence or not at latitude.总而言之,我想根据每个物种的存在与否在纬度上制作一个带有箱线图的图表。
You haven't provided much data, but is this what you're looking for?您没有提供太多数据,但这就是您要查找的数据吗?
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.