Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 多个并排箱线图';s:更改轴的大小_R_Plot_Ggplot2_Boxplot - Fatal编程技术网

R 多个并排箱线图';s:更改轴的大小

R 多个并排箱线图';s:更改轴的大小,r,plot,ggplot2,boxplot,R,Plot,Ggplot2,Boxplot,我很抱歉问了一个简单的问题,但我已经试图找到一个解决办法,而且我对制作复杂的情节还相当陌生。我有一个数据框(如下)包含四个变量:(1)采样站;(2) 蝙蝠种类;(3) 光照强度;(4)击球传球 我的目标是生成两个按变量Bat分组的地块。包含三个水平因子的物种:(1)Pipestrellus pygmaeus;(2) 风笛菌;(3)夜蛾: 绘图1: x轴——取样站(编号1:8); y轴-光。强度 绘图2: Sampling.Station.labels=c("1","2","3

我很抱歉问了一个简单的问题,但我已经试图找到一个解决办法,而且我对制作复杂的情节还相当陌生。我有一个数据框(如下)包含四个变量:(1)采样站;(2) 蝙蝠种类;(3) 光照强度;(4)击球传球

我的目标是生成两个按变量Bat分组的地块。包含三个水平因子的物种:(1)Pipestrellus pygmaeus;(2) 风笛菌;(3)夜蛾:

绘图1:

x轴——取样站(编号1:8); y轴-光。强度

绘图2:

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

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

         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(Light.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))
x轴——取样站(编号1:8); y轴-击球传球

我已经成功地从一个名为。下面的数据框是使用函数cbind生成的,以便添加名为Bat.passs的列,我正试图从中生成图2;但是,我一直收到这个警告消息,代码生成的是框和胡须图,而不是轴、轴标签或图例

Warning message:
In bxp(list(stats = c(2, 2, 3.5, 5, 5, 2, 3, 4, 6, 6, 1, 6, 10.5,  :
some notches went outside hinges ('box'): maybe set notch=FALSE 
有什么建议吗?我进行了一些搜索,但无法解决问题,也无法在Mac上使用R studio中的函数windows()打开窗口以增加绘图参数。任何帮助都将不胜感激

  windows(width=10, height=9)
  Error: could not find function "windows"
图1示例

绘图1的代码:

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

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

         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(Light.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))
Sampling.Station.labels=c(“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”)

bat.labels您的代码没有完全执行,命令
data\u long我不认为“notch”警告是轴的问题(即,这些可能是无关的),您可以设置
notch=FALSE
,就像它建议确认的那样。您也可以设置
bat.labels
,如下所示(即更短):
bat.labels Hey Steveb,抱歉,是,代码丢失。额外的代码有帮助吗?您的代码没有完全执行,命令
data\u long我不认为“notch”警告是轴的问题(即,这些可能是无关的),您可以设置
notch=FALSE
,就像建议确认的那样。您还可以设置
bat.labels
,如下所示(即更短):
bat.Hey Steveb,对不起,是的,代码丢失了。额外的代码有用吗?
 bats1<-structure(list(Sampling.Station = 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), Light.Intensity.S = 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), Number.of.bat.passes = c(3L, 2L, 
      5L, 6L, 15L, 2L, 10L, 12L, 17L, 2L, 0L, 0L, 15L, 7L, 17L, 0L, 
      1L, 0L, 14L, 10L, 12L, 7L, 4L, 1L, 3L, 5L, 3L, 1L, 6L, 11L, 3L, 
      0L, 0L, 12L, 11L, 9L, 1L, 2L, 1L, 12L, 14L, 10L, 3L, 2L, 1L, 
      5L, 4L, 2L), Saparano.Pipestrelle = 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), Common.Pipestrelle = c(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), Noctule = c(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)), .Names = c("Sampling.Station",        "Light.Intensity.S", 
     "Number.of.bat.passes", "Saparano.Pipestrelle",     "Common.Pipestrelle", 
      "Noctule"), row.names = c(NA, -48L), class = "data.frame")