由一个数值变量分组的多个并排堰体 [英] Multiple side-by-side barplots grouped by one numerical variable

查看:208
本文介绍了由一个数值变量分组的多个并排堰体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉提出一个简单的问题,但我试图在过去几天找到解决方案。在下面的数据框中的Sampling.Station.Number下有8个级别。因此,我试图产生一个并列的barplot,显示三个蝙蝠物种每个采样站检测称为:(1)Pipestrellus pygmaeus; (2)Pipestrellus pipestrellus;和(3)nyctalus noctula。

任何建议如何做到这一点?我做了一些搜索,但我只能在x轴上找到因子的例子,而不是通过数值变量分组的变量,任何帮助将不胜感激!



最后,我想要生成一个与我创建的boxplot格式相同的barplot:



我使用下面的代码创建了这些boxplot:

  Sampling.Station.labels = c 1,2,3,4,5,6,7,8)

bat.labels< -c(Pipistrellus pygmaeus ,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus管道,烟草夜蛾,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula,
Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus noctula)


data_long < - collect(bats1,x,Mean.Value,Saparano.Pipestrelle:Noctule)
head(data_long)

stacked.data.1< -melt(data_long,id = c('Sampling。站''''))
头(stacked.data.1)
str(stacked.data.1)


stacked.data.1 = stacked.data.1 [,-3]
头(stacked.data.1)
colnames(stacked.data.1)LT; -c( Sampling.Station, Bat.Species ,Light.Intensity)
head(stacked.data.1)


par(mfrow = c(1,1))
boxplots.double.1 = boxplot(Lighty.Intensity〜Sampling.Station + Bat.Species,
data = stacked.data.1,
at = c(1:24),
ylim = c(min(0,min(0)),
max(30,na.rm = T)),
xaxt =n ,
notch = TRUE,
col = c(red,blue,green),
cex.axis = 0.7,
cex.labels = 0.7,
ylab =Light Intensity(Lux),
xlab =采样站,
space = 1)

轴(side = 1,at = seq (3,24,by = 1),labels = FALSE)
text(seq(3,24,by = 3),par(usr)[3] - 0.2,labels = unique(Sampling.Station 。标签),srt = 45,pos = 1,xpd = TRUE,cex = 0.8)
par(oma = c(4,1,1,1))
par(fig = c(0,1 ,0,1),oma = c(0,0,0,0),mar = c(0,0,0,0),new = TRUE)
plot(0,0,type =n ,bty =n,xaxt =n,yaxt =n)
legend(top,
legend = c(Pipistrellus pygmaeus,Pipestrellus pipestrellus,Nyctalus ),
fill = c(Blue,Red,Green),
xpd = TRUE,horiz = TRUE,
inset = c(0,0),
bty =n,
col = 1:4,
cex = 0.8,
title =蝙蝠种,
lty = c(1,1 ))

我想Richard的建议,但我仍然遇到此错误消息,会有人能够帮助。非常感谢,如果可能的话:

  data =格式

数据结构:

'data.frame':144 obs。的5个变量:
$ Sampling.Station:NUM 1 1 1 2 2 2 3 3 3 4 ...
$ Light.Intensity.S:NUM 26.9 25.2 29.8 39 21.8 ...
$ Number.of.bat.passes:num 3 2 5 6 15 2 10 12 17 2 ...
$ Bat.Species:因子w / 3等级Common.Pipestrelle,..:3 3 3 3 3 3 3 3 3 3 ...
$ Simpsons.Index:NUM 0.4444 0 0 0.0278 0 ...

DF%GT;%
聚集(键=蝙蝠(station = as.factor(station))%>%
ggplot(aes(x = station,y = value,colour,value = value,-station)%>%
mutate =变量))+
geom_boxplot()+
facet_grid(〜bat.species,scales =free_y)


eval中的错误(expr, envir,enclos):object'Sampling.Station'not found **

Dataframe <

pre $ bats1 <-structure(list(Sampling.Station = c(1,1,1,2,2,2) ,3,3,3,
4,4,4,5,5,5,6,6,7,7,7 ,8,8,2,2,2,3,3,3,
4,4,4,5,5,5,6,6,6,7,7,7,8,8 ,8,1,1,1,1,1,1,
2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7 ,7,7,8,8,8,
2,2,2,3,3,3,4,4,4,5,5,5,6,6,7,7,7 ,8,8,8,
1,1,1,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6 ,6,
7,7,7,8,8,8,2,2,3,3,4,4,4,5,5,6,6,6,$ (b $ b 7,7,7,8,8,8,1,1,1),Light.Intensity = c(26.9,25.16,
39,29.81,21.83,20.22,2.9,2.1,0.85, 0.26,0.39,0.26,24.7,
21.99,20.46,26.32,0,0.43,0.02,0.02,0.03,0.02,0.03,$ b $ 293.56,167.79,114.06,17.22,16.26,4.76, 0.63,0.63,0.56,0.56,
86.63,87.97,88.59,0.31,0.04,0.05,0,0.01,0.01,0.02,2.6, 29.81,21.83,20.22,
2.9,2.1,0.85,0.62,0.39,0.26,24.7,21.99,20.46,26.32,
0,0.43,0.02,0.02,0.03,0.02,0.03, 293.56,167.79,114.06,
17.22,16.26,4.76,0.63,0.56,0.56,86.63,87.97,88.59,0。 31,
0.04,0.05,0,0.01,0.01,0.02,2.6,2.68,2.62,0.43,0.44,
26.9,25.16,39,29.81,21.83,20.22,2.9,2.1,0.85, 0.62,0.39,
0.26,24.7,21.99,20.46,26.32,0,0.43,0.02,0.02,0.03,
0.02,0.03,293.56,167.79,114.06,17.22,16.26,4.76, 0.63,
0.56,0.56,86.63,87.97,88.59,0.31,0.04,0.05,0,0.01,0.01,
0.02,2.6,2.68,2.62,0.43,0.44),数量.passes = c(3,
2,5,6,15,2,10,12,17,2,0,0,15,7,17​​,0,1,0,14,
10,12,7,4,1,3,5,3,1,6,11,3,0,0,12,11,9,1,2,
1,12,14,10 ,3,2,1,5,4,2,3,2,5,6,15,2,10,12,17,
2,0,0,15,7,17​​,0,1 ,0,14,10,12,7,4,1,3,5,3,1,
6,11,3,0,0,12,11,9,1,2,1,12 ,14,10,3,2,1,5,4,
2,3,2,5,6,15,2,10,12,17,2,0,0,15,7,17 ,0,1,0,
14,10,12,7,4,1,3,5,3,1,6,11,3,0,0,12,11,9,1,...,
2,1,12,14,10,3,2,1,5,4,2),Bat.Species = structure(c(3L ,
3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,
3L, ,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L, 3L,3L,3L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L, ,1L,1L,1L,1L,1L,1L,1L,2L,
2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L, ,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L, ,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L),标签= c(Common.Pipestrelle,
Noctule,Saprano.Pipestrelle类别=因子),Simpsons.Index = c(0.444444444,
0,0,0.027777778,0,0,0.25,0,0.08650519,0,0,0,0.111111111,
0,0.124567474 ,0,0,0,0.25,0.01,0.111111111,0.081632653,
0,0,0,0.04%,0,1,0.027777778,0.033057851,0.111 111111,0,
0,0.027777778,0.074380165,0.012345679,0,0.1,0.1373611111,
0.081632653,0.16,1,0.25,0,0.04,0.25,0.25,0.25,0.0,0.0,
7分配,0,0,0,0,0.08,0,0,0,0.6%,0,0.222222222,0,0,0,0.142857143,
9分配,0.5%,1.25,0,0, 0,4,0,0,5,2,1,0,0,1.25,0.888888889,
5分配,0,0,2,0.28,0.625,0.375,0,1,0,4,0.5%, 1,0,0,1,
0,0.109375,0,0,0,0.75,0,0,0,0,0.08,0.046875,0,0,
0,0,0, 0.046875,0,0,0,0,0.0625,0,0,0,0.015625,0,
0,0,0.28 0 0.12,0,0,0,0,0,0,0, 0,0,0,0,0)),row.names = c(NA,
-144L),.Names = c(Sampling.Station,Light.Intensity,Number.of。 bat.passes,
Bat.Species,Simpsons.Index),class =data.frame)


解决方案

我不确定你在做什么。这是我会用这些数据做的。

  library(dplyr)这是一个很好的例子, )
library(tidyr)
library(ggplot2)

df%>%
gather(key = variable,value = value,-Sampling .Station.Number)%>%
mutate(Sampling.Station.Number = as.factor(Sampling.Station.Number))%>%
ggplot(aes(x = Sampling.Station。 Number,y = value,color = variable))+
geom_boxplot()+
facet_wrap(〜variable,scales =free_y)
$ b

数据

  df < - (1L,1L,1L,2L,2L,
2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L,6L, 6L,7L,7L,7L,
8L,8L,8L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L, 6L,7L,7L,7L,8L,8L,8L,1L,1L,1L),光谱仪= c(26.9,
25.16,39,29.81,21.83,20.22,2.9,2.1,0.85,0.62,0.39 ,0.26,
24.7,2 1.99,20.46,26.32,0,0.43,0.02,0.02,0.03,0.02,
0.03,293.56,167.79,114.06,17.22,16.26,4.76,0.63,0.56,
0.56,86.63, 87.97,88.59,0.31,0.04,0.05,0,0.01,0.01,0.02,
2.6,2.68,2.62,0.43,0.44),D.SP = c(0.667,0.0,0.167,0.0, b $ B0,0.5,0,0.294mmol,0,0,0,0.333,0,0.353,0,0,0,0.5,0.1,
0.333,0.286,0,0,0,0.2,0 ,0.167,0.1820,0.333,0,0,0 $ b 0.167,0.273,0.111,0,0.1,0.417,0.286,0.4,1,0.5,0,0.2,
0.5,0.5 ),D.CP = c(0.333,1,0.4,1.167,0.533,1,0.1677,
0.118,0,0,0,1,0.714,0.471,0,1,0,0.5, 0.9,0.667,0.714,
1,1,1,0.8,1,0,0.833,0.727,0.333,0,0,0.417,0.727,
0.556,1,1,2,0.583, 0.714,0.6,0,0.5,1,0.8,0.5,0.5),
DN = C(0,0,0.8,0,0.467,0,0,0,0.176,1,0,0,0 ,
0.286,0.176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0.091,0,0,0,0.583 ,0,0.333,0,0,0,0,0,0,0
0,0,0,0,0)),.Names = c(Sampling.Stat离子数,光谱仪,
D.SP,D.CP,DN),class =data.frame,row.names = c(1,
2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,
36,37,38,39,40,41,42,43,44,45,46,
47 ,48))


I apologise for asking a simple question but I have tried to find a solution over the last couple of days. There are 8 levels under Sampling.Station.Number in the data frame below. Therefore, I am attempting to produce a side-by-side barplot showing three bars per sampling station for three bat species detected called: (1) Pipestrellus pygmaeus; (2) Pipestrellus pipestrellus; and (3)nyctalus noctula.

Any suggestions how to do that? I made some searches but I only find examples for factors on the x axis, not variables grouped by a numerical variable, any help will be appreciated!

In the end I want to produce a barplot that has the same format as this boxplot, which I constructed:

I created these boxplot's with this code below:

         Sampling.Station.labels=c("1","2","3","4","5","6","7","8")

         bat.labels<-c("Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula",
                       "Pipistrellus pygmaeus", "Pipestrellus pipestrellus", "Nyctalus noctula")


         data_long <- gather(bats1, x, Mean.Value, Saparano.Pipestrelle:Noctule)
         head(data_long) 

         stacked.data.1<-melt(data_long, id=c('Sampling.Station', 'x'))
         head(stacked.data.1)
         str(stacked.data.1)


         stacked.data.1=stacked.data.1[, -3]
         head(stacked.data.1)
         colnames(stacked.data.1)<-c("Sampling.Station", "Bat.Species", "Light.Intensity") 
         head(stacked.data.1)


         par(mfrow = c(1,1))
         boxplots.double.1=boxplot(Lighty.Intensity~Sampling.Station + Bat.Species, 
                                   data = stacked.data.1, 
                                   at = c(1:24), 
                                   ylim = c(min(0, min(0)), 
                                            max(30, na.rm = T)),
                                   xaxt = "n",
                                   notch=TRUE,
                                   col = c("red", "blue", "green"),
                                   cex.axis=0.7,
                                   cex.labels=0.7,
                                   ylab="Light Intensity (Lux)", 
                                   xlab="Sampling Stations",
                                   space=1)

         axis(side = 1, at = seq(3, 24, by = 1), labels = FALSE)
         text(seq(3, 24, by=3), par("usr")[3] - 0.2, labels=unique(Sampling.Station.labels), srt = 45, pos = 1, xpd = TRUE, cex=0.8)
         par(oma = c(4, 1, 1, 1))
         par(fig = c(0, 1, 0, 1), oma = c(0, 0, 0, 0), mar = c(0, 0, 0, 0), new = TRUE)
         plot(0, 0, type = "n", bty = "n", xaxt = "n", yaxt = "n")
         legend("top", 
                legend=c("Pipistrellus pygmaeus","Pipestrellus pipestrellus","Nyctalus noctula"),
                fill=c("Blue", "Red", "Green"),
                xpd = TRUE, horiz = TRUE, 
                inset = c(0,0), 
                bty = "n", 
                col = 1:4, 
                cex = 0.8,
                title = "Bat Species",
                lty = c(1,1))

I tried Richard's suggestion but I am still experiencing this error message, would anyone be able to help. Many thanks in advance if this is possible:

   data=format

   Data structure: 

   'data.frame':    144 obs. of  5 variables:
     $ Sampling.Station    : num  1 1 1 2 2 2 3 3 3 4 ...
     $ Light.Intensity.S   : num  26.9 25.2 39 29.8 21.8 ...
     $ Number.of.bat.passes: num  3 2 5 6 15 2 10 12 17 2 ...
     $ Bat.Species         : Factor w/ 3 levels       "Common.Pipestrelle",..: 3 3 3 3 3 3 3 3 3 3 ...
     $ Simpsons.Index      : num  0.4444 0 0 0.0278 0 ...

       df %>% 
       gather(key = bat.species, value = value, -station) %>%
       mutate(station = as.factor(station)) %>%
       ggplot(aes(x = station, y = value, colour = variable)) +
       geom_boxplot() + 
       facet_grid(~bat.species, scales = "free_y")


       **Error in eval(expr, envir, enclos) : object 'Sampling.Station' not found**

Dataframe

bats1<-structure(list(Sampling.Station = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 
4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 2, 2, 2, 3, 3, 3, 
4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 1, 1, 1, 1, 1, 1, 
2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 
2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 
1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 
7, 7, 7, 8, 8, 8, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 
7, 7, 7, 8, 8, 8, 1, 1, 1), Light.Intensity = c(26.9, 25.16, 
39, 29.81, 21.83, 20.22, 2.9, 2.1, 0.85, 0.62, 0.39, 0.26, 24.7, 
21.99, 20.46, 26.32, 0, 0, 0.43, 0.02, 0.02, 0.03, 0.02, 0.03, 
 293.56, 167.79, 114.06, 17.22, 16.26, 4.76, 0.63, 0.56, 0.56, 
 86.63, 87.97, 88.59, 0.31, 0.04, 0.05, 0, 0.01, 0.01, 0.02, 2.6, 
 2.68, 2.62, 0.43, 0.44, 26.9, 25.16, 39, 29.81, 21.83, 20.22, 
 2.9, 2.1, 0.85, 0.62, 0.39, 0.26, 24.7, 21.99, 20.46, 26.32, 
 0, 0, 0.43, 0.02, 0.02, 0.03, 0.02, 0.03, 293.56, 167.79, 114.06, 
 17.22, 16.26, 4.76, 0.63, 0.56, 0.56, 86.63, 87.97, 88.59, 0.31, 
 0.04, 0.05, 0, 0.01, 0.01, 0.02, 2.6, 2.68, 2.62, 0.43, 0.44, 
 26.9, 25.16, 39, 29.81, 21.83, 20.22, 2.9, 2.1, 0.85, 0.62, 0.39, 
  0.26, 24.7, 21.99, 20.46, 26.32, 0, 0, 0.43, 0.02, 0.02, 0.03, 
  0.02, 0.03, 293.56, 167.79, 114.06, 17.22, 16.26, 4.76, 0.63, 
  0.56, 0.56, 86.63, 87.97, 88.59, 0.31, 0.04, 0.05, 0, 0.01, 0.01, 
  0.02, 2.6, 2.68, 2.62, 0.43, 0.44), Number.of.bat.passes = c(3, 
  2, 5, 6, 15, 2, 10, 12, 17, 2, 0, 0, 15, 7, 17, 0, 1, 0, 14, 
  10, 12, 7, 4, 1, 3, 5, 3, 1, 6, 11, 3, 0, 0, 12, 11, 9, 1, 2, 
  1, 12, 14, 10, 3, 2, 1, 5, 4, 2, 3, 2, 5, 6, 15, 2, 10, 12, 17, 
  2, 0, 0, 15, 7, 17, 0, 1, 0, 14, 10, 12, 7, 4, 1, 3, 5, 3, 1, 
  6, 11, 3, 0, 0, 12, 11, 9, 1, 2, 1, 12, 14, 10, 3, 2, 1, 5, 4, 
  2, 3, 2, 5, 6, 15, 2, 10, 12, 17, 2, 0, 0, 15, 7, 17, 0, 1, 0, 
  14, 10, 12, 7, 4, 1, 3, 5, 3, 1, 6, 11, 3, 0, 0, 12, 11, 9, 1, 
  2, 1, 12, 14, 10, 3, 2, 1, 5, 4, 2), Bat.Species = structure(c(3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label =           c("Common.Pipestrelle", 
 "Noctule", "Saprano.Pipestrelle"), class = "factor"), Simpsons.Index =           c(0.444444444, 
  0, 0, 0.027777778, 0, 0, 0.25, 0, 0.08650519, 0, 0, 0, 0.111111111, 
  0, 0.124567474, 0, 0, 0, 0.25, 0.01, 0.111111111, 0.081632653, 
  0, 0, 0, 0.04, 0, 1, 0.027777778, 0.033057851, 0.111111111, 0, 
  0, 0.027777778, 0.074380165, 0.012345679, 0, 0, 1, 0.173611111, 
  0.081632653, 0.16, 1, 0.25, 0, 0.04, 0.25, 0.25, 0.25, 0, 0, 
  7, 0, 0, 0, 0, 0.08, 0, 0, 0, 0.6, 0, 0.222222222, 0, 0, 0, 0.142857143, 
  9, 0.5, 1.25, 0, 0, 0, 4, 0, 0, 5, 2, 1, 0, 0, 1.25, 0.888888889, 
  5, 0, 0, 2, 0.28, 0.625, 0.375, 0, 1, 0, 4, 0.5, 1, 0, 0, 1, 
  0, 0.109375, 0, 0, 0, 0.75, 0, 0, 0, 0, 0.08, 0.046875, 0, 0, 
  0, 0, 0, 0.046875, 0, 0, 0, 0, 0.0625, 0, 0, 0, 0.015625, 0, 
  0, 0, 0.28, 0, 0.12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names =    c(NA, 
  -144L), .Names = c("Sampling.Station", "Light.Intensity",         "Number.of.bat.passes", 
   "Bat.Species", "Simpsons.Index"), class = "data.frame")

解决方案

I am not exactly sure what you are after. This is what I would do with these data. I've used boxplots rather than barcharts as I think the latter are generally fairly useless for displaying variation.

library("dplyr")
library("tidyr")
library("ggplot2")

df %>% 
  gather(key = variable, value = value, -Sampling.Station.Number) %>%
  mutate(Sampling.Station.Number = as.factor(Sampling.Station.Number)) %>%
  ggplot(aes(x = Sampling.Station.Number, y = value, colour = variable)) +
  geom_boxplot() + 
  facet_wrap(~variable, scales = "free_y")

Data

df <- structure(list(Sampling.Station.Number = c(1L, 1L, 1L, 2L, 2L, 
2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 
8L, 8L, 8L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 
6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 1L, 1L, 1L), Spectrometer = c(26.9, 
25.16, 39, 29.81, 21.83, 20.22, 2.9, 2.1, 0.85, 0.62, 0.39, 0.26, 
24.7, 21.99, 20.46, 26.32, 0, 0, 0.43, 0.02, 0.02, 0.03, 0.02, 
0.03, 293.56, 167.79, 114.06, 17.22, 16.26, 4.76, 0.63, 0.56, 
0.56, 86.63, 87.97, 88.59, 0.31, 0.04, 0.05, 0, 0.01, 0.01, 0.02, 
2.6, 2.68, 2.62, 0.43, 0.44), D.SP = c(0.667, 0, 0, 0.167, 0, 
0, 0.5, 0, 0.294, 0, 0, 0, 0.333, 0, 0.353, 0, 0, 0, 0.5, 0.1, 
0.333, 0.286, 0, 0, 0, 0.2, 0, 1, 0.167, 0.182, 0.333, 0, 0, 
0.167, 0.273, 0.111, 0, 0, 1, 0.417, 0.286, 0.4, 1, 0.5, 0, 0.2, 
0.5, 0.5), D.CP = c(0.333, 1, 0.4, 1.167, 0.533, 1, 0, 0.167, 
0.118, 0, 0, 0, 1, 0.714, 0.471, 0, 1, 0, 0.5, 0.9, 0.667, 0.714, 
1, 1, 1, 0.8, 1, 0, 0.833, 0.727, 0.333, 0, 0, 0.417, 0.727, 
0.556, 1, 1, 2, 0.583, 0.714, 0.6, 0, 0.5, 1, 0.8, 0.5, 0.5), 
    D.N = c(0, 0, 0.8, 0, 0.467, 0, 0, 0, 0.176, 1, 0, 0, 0, 
    0.286, 0.176, 0, 0, 0, 0, 0, 0.25, 0, 0, 0, 0, 0.2, 0, 0, 
    0, 0.091, 0, 0, 0, 0.583, 0, 0.333, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0)), .Names = c("Sampling.Station.Number", "Spectrometer", 
"D.SP", "D.CP", "D.N"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", 
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", 
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", 
"47", "48"))

这篇关于由一个数值变量分组的多个并排堰体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆