-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSec_heatmap.R
More file actions
70 lines (47 loc) · 2.1 KB
/
Sec_heatmap.R
File metadata and controls
70 lines (47 loc) · 2.1 KB
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
rm(list = ls())
#install.packages('ggDoubleHeat')
library(ggDoubleHeat)
library(ggplot2)
library(tidyverse)
library(readr)
library(dplyr)
# Load the extrafont package and import the registered fonts
library(extrafont)
font_import(paths = "/Users/sophiazhang/Library/Fonts/", pattern = "Myriad Pro")
# Load the fonts for use in ggplot2
loadfonts()
dt<- read_csv("./Results/TechProExtreme/trloss.csv")
head(dt)
##geom_heat_tri
# Define the order of levels for the Sector factor
sector_order <- unique(dt$Sector)
sector_order <- rev(sector_order)
# Convert Sectors to a factor with the desired order
dt$Sector <- factor(dt$Sector, levels = sector_order)
dt <- dt[order(dt$Sector), ]
# Define the order of levels for the Scenario factor
scenario_order <- unique(dt$Scenario)
dt$Scenario <- factor(dt$Scenario, levels = scenario_order)
dt <- dt[order(dt$Scenario), ]
# Filter data to keep values greater than 0.2
filtered_dt <- dt %>%
filter(SSP126 > 0.15 | SSP585 > 0.15)
p2<- ggplot(dt, aes(x = Scenario, y = Sector)) +
geom_heat_tri(lower = SSP126,
upper= SSP585,
lower_colors= c( "#abdda4", "#e6f598", "#fee08b", "#fdae6e", "#f46d43", "#d53e4f"),
upper_colors= c( "#abdda4", "#e6f598", "#fee08b", "#fdae6e", "#f46d43", "#d53e4f")) +
geom_text(data = filtered_dt, aes(x = Scenario, y = Sector, label = round(SSP126, 2)),
color = "black", size = 3, hjust = 1.5, vjust = 1.2) +
geom_text(data = filtered_dt, aes(x = Scenario, y = Sector, label = round(SSP585, 2)),
color = "black", size = 3, hjust = -0.5, vjust = -0.2) + # Adjust these parameters as needed
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, color = "black", size = 12),
axis.text.y = element_text(color = "black", size = 12),
legend.text = element_text(color = "black", size = 12),
text = element_text(family = "Myriad Pro")
)
# Remove x-axis and y-axis labels
p2 <- p2 +
labs(x = NULL, y = NULL)
ggsave("./FigExtreme/sec_heatmap.png", p2, width = 12, height = 8, dpi = 300)