-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rbarchart_area_v4_compareMapResults_FINAL.R
140 lines (114 loc) · 5.49 KB
/
Rbarchart_area_v4_compareMapResults_FINAL.R
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#Make a bar chart
#Crystal Wespestad (SIG) March, 2022
#####################################################################
library(survey)
library(tidyverse)
library(knitr)
library(rmarkdown)
library(tidyr)
library(networkD3)
library(tidyverse)
library(dplyr)
library(scales)
#library(lubridate)
setwd("C:\\Users\\cryst\\OneDrive\\Documents\\Philippines\\PhilippinesQAQCanalysis")
# area csv
#dataarea_NEW <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_NEW.csv') #R results
#dataarea_NEW <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_NEW_OlafssonWay.csv')
#dataarea_NEW <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_NEW_OlafssonWay_v4.csv')
dataarea_NEW <- read.csv('Results\\FINAL_NewStratMap_AE_CI_forgraph_v2.csv')
dataarea_NEW$phase<-'2.FINAL929_reviewed'
dataarea_NEW
# area csv
#dataarea_old <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_Old.csv') #R results
#dataarea_old <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_OLD_OlafssonWay.csv')
#dataarea_old <- read.csv('Results\\AreasofDisturbance_ceoV4version_SAVE_OLD_OlafssonWay_v2.csv')
dataarea_old <- read.csv('Results\\FINALOLD850_NewStratMap_AE_CI_forgraph_v2.csv')
dataarea_old$phase<-'1.Only850_reviewed'
colnames(dataarea_old)[1]<-"Strata"
dataarea_old
dataarea_BEFOREREVIEW <- read.csv('Results\\BEFOREREVIEW850_NewStratMap_AE_CI_forgraph_v2.csv')
dataarea_BEFOREREVIEW$phase<-'3.Only850_IMPOSSIBLES_present'
colnames(dataarea_old)[1]<-"Strata"
dataarea_BEFOREREVIEW
#dataarea_sim50ideal <- read.csv('Results\\BestCase50NewMapSimulation_AE_CI_forgraph_v1.csv')
#dataarea_sim50ideal$phase <- '6.Simulation50_AllNewPointsAgreeWithMap'
#colnames(dataarea_sim50ideal)[1] <- "Strata"
#
#dataarea_sim35ideal <- read.csv('Results\\BestCase35NewMapSimulation_AE_CI_forgraph_v1.csv')
#dataarea_sim35ideal$phase <- '4.Simulation35_AllNewPointsAgreeWithMap'
#colnames(dataarea_sim35ideal)[1] <- "Strata"
#
#
#dataarea_sim50realistic <- read.csv('Results\\realisticSim50_AE_CI_forgraph_v1.csv')
#dataarea_sim50realistic$phase <- '5.Simulation50_RealisticMapAgreement'
#colnames(dataarea_sim50realistic)[1] <- "Strata"
#dataarea_sim35realistic <- read.csv('Results\\realisticSim35_AE_CI_forgraph_v1.csv')
#dataarea_sim35realistic$phase <- '3.Simulation35_RealisticMapAgreement'
#colnames(dataarea_sim35realistic)[1] <- "Strata"
?comma_format()
#type.convert(dataarea_NEW$Area, as.is=TRUE) ###kinda helped
##########################################################################
# SWITCH THE UNCOMMENT DATATEST ROW HERE FOR PLOTTING DIFFERENT COMBOS
##########################################################################
#This is all of them
#dataTest <- rbind(dataarea_old, dataarea_NEW, dataarea_sim50ideal,dataarea_sim50realistic, dataarea_sim35ideal,dataarea_sim35realistic)
#This is just Old and New
#dataTest <- rbind(dataarea_old, dataarea_NEW)
#This is just for 35 points plus new
dataTest <- rbind(dataarea_old, dataarea_NEW, dataarea_BEFOREREVIEW)
dataTest$AElab <- comma_format()(dataTest$AE)
#dataTest$Arealab <- 1
dataTest$CIlab <- paste0('+/- ', comma_format()(dataTest$CI))
###above got error: Error in x * scale : non-numeric argument to binary operator
dataTest$MOElab <- comma_format()(dataTest$MOE*100)
dataTest$MOElab <- as.numeric(dataTest$MOElab)
dataTest$MOElab <- sprintf(dataTest$MOElab,fmt = '%#.1f')
#dataTest$MOElab <- as.character(dataTest$MOElab)
data <- data.frame(dataTest)
#vLABELH <- c(145813,152997,90409,160376,286795,355990,346318)
# Calculate y position, placing it in the middle
####BELOW GETS LOTS OF ERRORS####
data <- data %>%
group_by(Strata) %>%
#mutate(label_y = cumsum(Area) - 0.5 * Area)
mutate(label_y = cumsum(AE) -cumsum(AE))
# Calculate error position, placing it above
data <- data %>%
group_by(Strata) %>%
mutate(label_error = CI+AE)
# Most basic error bar
AE_CI_plot <- ggplot(data, aes(fill= phase, x = Strata, y = AE )) +
geom_bar(position="dodge", stat="identity", alpha=1) +
geom_errorbar(aes(ymin = AE - CI, ymax = AE + CI),
width = 0.2, colour = "black",
position = position_dodge(.9)) +
geom_text(aes(label = AElab, y = label_error), position = position_dodge(.9),
vjust = -0.4, hjust = -0.45, colour = "black", size=2.4, angle=90)+
geom_text(aes(label = CIlab, y = label_error), position = position_dodge(.9),
vjust = 0.9, hjust = -0.45, colour="black", size=2.2, angle=90) +
geom_text(aes(label = MOElab, y = label_error), position = position_dodge(0.9),
vjust = -0.4, colour = "red", size=2.2)+
xlab('Activity Classes') + # for the x axis label
ylab('Area, ha') + scale_y_continuous(labels = comma)+
expand_limits(y=16500000)
AE_CI_plot
ggsave("my_AE_CI_plot_FINAL_withB4imossiblereview.jpeg",width = 14, height = 6, units = c("in"), dpi = 300)
dev.off()
graphics.off()
#plot the MOE values, the uncertainty %, for all categories
dataMOE <- data.frame(dataTest)
dataMOE <- dataMOE %>%
group_by(Strata) %>%
mutate(label_error = MOE*100)
MOEplot <- ggplot(dataMOE, aes(fill= phase, x = Strata, y = MOE*100 )) +
geom_bar(position="dodge", stat="identity", alpha=1) +
geom_text(aes(label = MOElab, y = label_error), position = position_dodge(0.9),
hjust = -0.3, colour = "red", size=2.2, angle = 90)+
xlab('Activity Classes') + # for the x axis label
ylab('Margin of Error (%)') + scale_y_continuous(labels = comma)+
expand_limits(y=60)
MOEplot
ggsave("my_MOE_FINAL_withB4imossiblereview.jpeg",width = 10, height = 6, units = c("in"), dpi = 300)
dev.off()
graphics.off()