我将解释我的数据是如何构建的以及我想要展示的内容。
树木直径数据,在14个月内进行测量。
在2个不同的站点收集数据,每个站点都有很多 个体
我需要建立一个" double" timeseries boxplot(按年月)/网站。 每年 - 每月将有2个盒子,一个来自site1,另一个来自站点2。
我已经在excel中构建了它,但是负值显示错误。
我不知道如何使用R构建它,但是有一些提示可能我可以构建它。
由于
这是我数据的输入:
!数据DPUT
structure(list(DATE = structure(c(10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 11L, 13L, 12L, 14L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 11L, 13L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 13L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L, 10L, 12L, 14L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L,
13L), .Label = c("01/01/2011", "01/02/2011", "01/03/2011", "01/04/2011",
"01/05/2011", "01/06/2011", "01/07/2011", "01/08/2011", "01/09/2011",
"01/10/2010", "01/10/2011", "01/11/2010", "01/11/2011", "01/12/2010"
), class = "factor"), VALUE = structure(c(22L, 46L, 47L, 61L,
20L, 48L, 38L, 14L, 3L, 37L, 1L, 17L, 17L, 40L, 15L, 26L, 66L,
34L, 53L, 55L, 59L, 17L, 18L, 17L, 15L, 18L, 15L, 22L, 25L, 38L,
63L, 28L, 45L, 55L, 44L, 15L, 14L, 20L, 15L, 20L, 20L, 26L, 24L,
12L, 60L, 46L, 50L, 47L, 26L, 14L, 2L, 14L, 14L, 17L, 17L, 25L,
37L, 18L, 51L, 54L, 52L, 67L, 14L, 14L, 14L, 15L, 14L, 20L, 25L,
22L, 22L, 1L, 24L, 47L, 24L, 24L, 23L, 20L, 17L, 15L, 1L, 15L,
15L, 39L, 17L, 46L, 14L, 14L, 18L, 59L, 60L, 20L, 18L, 2L, 14L,
2L, 15L, 41L, 23L, 56L, 61L, 17L, 17L, 18L, 38L, 11L, 23L, 15L,
18L, 14L, 23L, 14L, 1L, 15L, 14L, 14L, 14L, 14L, 1L, 14L, 2L,
14L, 14L, 15L, 14L, 17L, 17L, 61L, 28L, 53L, 24L, 24L, 17L, 20L,
15L, 18L, 25L, 65L, 15L, 1L, 44L, 14L, 14L, 14L, 7L, 9L, 17L,
24L, 15L, 17L, 18L, 15L, 1L, 53L, 18L, 44L, 58L, 22L, 20L, 23L,
15L, 37L, 14L, 18L, 14L, 49L, 8L, 49L, 59L, 30L, 31L, 17L, 17L,
17L, 18L, 24L, 18L, 26L, 15L, 38L, 4L, 41L, 27L, 31L, 42L, 14L,
14L, 62L, 17L, 24L, 15L, 15L, 15L, 15L, 14L, 45L, 60L, 33L, 53L,
1L, 3L, 68L, 15L, 49L, 7L, 15L, 18L, 38L, 24L, 20L, 24L, 14L,
15L, 8L, 15L, 26L, 1L, 14L, 17L, 18L, 3L, 45L, 56L, 61L, 33L,
38L, 45L, 13L, 18L, 26L, 14L, 22L, 17L, 38L, 17L, 3L, 57L, 64L,
64L, 51L, 51L, 23L, 17L, 41L, 1L, 3L, 14L, 17L, 14L, 36L, 15L,
24L, 23L, 21L, 21L, 14L, 1L, 18L, 15L, 14L, 15L, 37L, 15L, 23L,
22L, 24L, 25L, 19L, 19L, 20L, 2L, 2L, 17L, 1L, 15L, 22L, 15L,
26L, 35L, 9L, 51L, 25L, 25L, 18L, 1L, 1L, 18L, 15L, 17L, 25L,
1L, 10L, 41L, 32L, 45L, 5L, 5L, 53L, 1L, 20L, 17L, 2L, 14L, 15L,
24L, 4L, 6L, 43L, 24L, 16L, 16L, 17L, 14L, 15L, 14L, 17L, 15L,
2L, 18L, 15L, 45L, 28L, 22L, 50L, 50L, 15L, 8L, 29L, 22L, 17L,
24L, 17L), .Label = c("-0,2", "-0,4", "-0,6", "-0,8", "-0,9",
"-0,9998", "-1", "-1,2", "-2,2", "-2,8", "-3", "-3,2", "-4,4",
"0", "0,2", "0,3", "0,4", "0,6", "0,7", "0,8", "0,9", "1", "1,2",
"1,4", "1,6", "1,8", "10", "10,6", "10,8", "11,4", "11,6", "12,6",
"12,8", "13,6", "14,4", "17.998", "2", "2,2", "2,4", "2,6", "2,8",
"21,2", "23.998", "3", "3,2", "3,4", "3,6", "3,8", "4", "4,2",
"4,4", "4,6", "4,8", "5", "5,2", "5,4", "5,6", "5,8", "6,2",
"6,4", "6,6", "7,4", "7,8", "8", "8,2", "8,6", "8,8", "9,6"), class = "factor"),
INDIVIDUAL = structure(c(10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L), .Label = c("co01", "co02", "co03", "co04", "co05",
"co06", "co07", "co08", "co09", "jb01", "jb02", "jb03", "jb04",
"jb05", "jb06", "jb07", "jb08", "spvs01", "spvs02", "spvs03",
"spvs04", "spvs05", "spvs06", "spvs07"), class = "factor"),
SITE = structure(c(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, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,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 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("site1", "site2"), class = "factor")), .Names = c("DATE",
"VALUE", "INDIVIDUAL", "SITE"), class = "data.frame", row.names = c(NA,
-332L))
答案 0 :(得分:3)
您应该在绘图之前格式化数据:
dat$DATE <- as.Date(dat$DATE,"%d/%m/%Y")
dat$VALUE <- as.numeric(gsub(',','.',dat$VALUE))
然后使用ggplot2
,您可以执行以下操作:
library(ggplot2)
ggplot(dat) +
geom_boxplot(aes(x=format(dat$DATE,'%y %b'),y=VALUE,fill=SITE))
为了更好地了解您的数据如何因人而异,您可以使用heatmap
绘制geom_tile
:
ggplot(dat) +
geom_tile(aes(x=months(DATE),y=INDIVIDUAL,fill=VALUE)) +
facet_grid(SITE~.,scales="free")