简体   繁体   English

如何在 R 中制作此箱线图?

[英]How to make this boxplot in R?

I am trying to make a boxplot graph in R with ggplot2 like the one seen in the example figures.我正在尝试使用 ggplot2 在 R 中制作箱线图,就像在示例图中看到的那样。 In the "x" axis, the data of the boxplot would correspond in this case of NDVI of plant cover and in the "y" axis, the correlation values between the NDVI and another variable.在“x”轴上,箱线图的数据在这种情况下对应植物覆盖的 NDVI,在“y”轴上,对应于 NDVI 和另一个变量之间的相关值。 So far, you can only create the boxplot graph that shows the NDVI values on the "y" axis.到目前为止,您只能创建在“y”轴上显示 NDVI 值的箱线图。 Thanks for your help.谢谢你的帮助。

在此处输入图像描述

Add sample of my data, LANDUSE contains 3 types of vegetation cover: WETL, SHRU and BARR.添加我的数据样本,LANDUSE 包含 3 种植被覆盖类型:WETL、SHRU 和 BARR。 NDVI are the NDVI values for each cover and R2 the correlation of the NDVI values with other data (soil moisture), in total I only have three R2 data, each for the three types of plant cover. NDVI 是每个覆盖物的 NDVI 值,R2 是 NDVI 值与其他数据(土壤水分)的相关性,我总共只有三个 R2 数据,每个数据用于三种植物覆盖类型。

 LANDUSE    NDVI    R2
1   WETL    0.41490  0.71
2   WETL    0.35825  0.71
3   WETL    0.48040  0.71
4   WETL    0.46865  0.71
5   WETL    0.40155  0.71
6   WETL    0.32255  0.71
7   WETL    0.29695  0.71
8   WETL    0.27215  0.71
9   WETL    0.27560  0.71
10  WETL    0.25590  0.71
11  WETL    0.26100  0.71
12  WETL    0.25795  0.71
13  WETL    0.28835  0.71
14  WETL    0.41735  0.71
15  WETL    0.44215  0.71
16  WETL    0.48855  0.71
17  WETL    0.39070  0.71
18  WETL    0.31940  0.71
19  WETL    0.27780  0.71
20  WETL    0.25895  0.71
21  WETL    0.29435  0.71
22  WETL    0.29510  0.71
23  WETL    0.27760  0.71
24  WETL    0.29510  0.71
25  WETL    0.36605  0.71
26  WETL    0.40170  0.71
27  WETL    0.47175  0.71
28  WETL    0.47125  0.71
29  WETL    0.38540  0.71
30  SHRB    0.40545  0.78
31  SHRB    0.35295  0.78
32  SHRB    0.44720  0.78
33  SHRB    0.39525  0.78
34  SHRB    0.33565  0.78
35  SHRB    0.26720  0.78
36  SHRB    0.24750  0.78
37  SHRB    0.22590  0.78
38  SHRB    0.22220  0.78
39  SHRB    0.20930  0.78
40  SHRB    0.21205  0.78
41  SHRB    0.22265  0.78
42  SHRB    0.26165  0.78
43  SHRB    0.40230  0.78
44  SHRB    0.42050  0.78
45  SHRB    0.42760  0.78
46  SHRB    0.32310  0.78
47  SHRB    0.27360  0.78
48  SHRB    0.23945  0.78
49  SHRB    0.23050  0.78
50  SHRB    0.23655  0.78
51  SHRB    0.22880  0.78
52  SHRB    0.21850  0.78
53  SHRB    0.24015  0.78
54  SHRB    0.29850  0.78
55  SHRB    0.35620  0.78
56  SHRB    0.43130  0.78
57  SHRB    0.41165  0.78
58  SHRB    0.31965  0.78
59  SHRB    0.25735  0.78
60  BARR    0.19040  0.54
61  BARR    0.18645  0.54
62  BARR    0.24925  0.54
63  BARR    0.24545  0.54
64  BARR    0.21630  0.54
65  BARR    0.18645  0.54
66  BARR    0.17610  0.54
67  BARR    0.16485  0.54
68  BARR    0.16450  0.54
69  BARR    0.15730  0.54
70  BARR    0.16140  0.54
71  BARR    0.14540  0.54
72  BARR    0.15485  0.54
73  BARR    0.21290  0.54
74  BARR    0.24940  0.54
75  BARR    0.26325  0.54
76  BARR    0.20705  0.54
77  BARR    0.17210  0.54
78  BARR    0.13090  0.54
79  BARR    0.13335  0.54
80  BARR    0.17345  0.54
81  BARR    0.17155  0.54
82  BARR    0.16610  0.54
83  BARR    0.19005  0.54
84  BARR    0.20255  0.54
85  BARR    0.19690  0.54
86  BARR    0.25600  0.54
87  BARR    0.24950  0.54
88  BARR    0.20705  0.54
89  BARR    0.17955  0.54
Showing 1 to 15 of 89 entries, 3 total columns

You can try this.你可以试试这个。 I am not sure about your y var but I used NDVI :我不确定您的y var 但我使用了NDVI

library(ggplot2)

ggplot(df,aes(x=LANDUSE,y=NDVI,group=factor(R2)))+
  geom_boxplot()

在此处输入图像描述

Update更新

library(ggplot2)

ggplot(df,aes(x=LANDUSE,y=NDVI,fill=R2))+
    geom_boxplot()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM