heat: update granularity plot with modern ggplot
This commit is contained in:
parent
d1c32869c1
commit
63aa07dad5
@ -1,120 +1,67 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
library(scales)
|
||||
library(jsonlite)
|
||||
library(viridis, warn.conflicts = FALSE)
|
||||
library(stringr)
|
||||
|
||||
args = commandArgs(trailingOnly=TRUE)
|
||||
|
||||
# Read the timetable from args[1]
|
||||
input_file = "input.json"
|
||||
if (length(args)>0) { input_file = args[1] }
|
||||
# Set the input dataset if given in argv[1], or use "input" as default
|
||||
if (length(args)>0) { input_file = args[1] } else { input_file = "input" }
|
||||
|
||||
# Load the dataset in NDJSON format
|
||||
dataset = jsonlite::stream_in(file(input_file)) %>%
|
||||
jsonlite::flatten()
|
||||
df = jsonlite::stream_in(file(input_file), verbose=FALSE) %>%
|
||||
|
||||
jsonlite::flatten() %>%
|
||||
|
||||
# We only need the nblocks and time
|
||||
df = select(dataset, config.cbs, config.rbs, time) %>%
|
||||
rename(cbs=config.cbs, rbs=config.rbs)
|
||||
select(unit,
|
||||
config.cbs,
|
||||
config.rbs,
|
||||
time,
|
||||
total_time) %>%
|
||||
|
||||
df$cbs = as.factor(df$cbs)
|
||||
df$rbs = as.factor(df$rbs)
|
||||
rename(cbs=config.cbs,
|
||||
rbs=config.rbs) %>%
|
||||
|
||||
# Normalize the time by the median
|
||||
df=group_by(df, cbs, rbs) %>%
|
||||
mutate(mtime = median(time)) %>%
|
||||
mutate(tnorm = time / mtime - 1) %>%
|
||||
mutate(logmtime = log(mtime)) %>%
|
||||
ungroup() %>%
|
||||
filter(between(mtime, mean(time) - (1 * sd(time)),
|
||||
mean(time) + (1 * sd(time))))
|
||||
# Convert to factors
|
||||
mutate(cbs = as.factor(cbs)) %>%
|
||||
mutate(rbs = as.factor(rbs)) %>%
|
||||
mutate(unit = as.factor(unit)) %>%
|
||||
|
||||
ppi=300
|
||||
h=5
|
||||
w=5
|
||||
# Compute median times
|
||||
group_by(unit) %>%
|
||||
mutate(median.time = median(time)) %>%
|
||||
mutate(normalized.time = time / median.time - 1) %>%
|
||||
mutate(log.median.time = log(median.time)) %>%
|
||||
ungroup()
|
||||
|
||||
png("box.png", width=w*ppi, height=h*ppi, res=ppi)
|
||||
#
|
||||
#
|
||||
#
|
||||
# Create the plot with the normalized time vs nblocks
|
||||
p = ggplot(data=df, aes(x=cbs, y=tnorm)) +
|
||||
dpi = 300
|
||||
h = 6
|
||||
w = 6
|
||||
|
||||
# Labels
|
||||
labs(x="cbs", y="Normalized time",
|
||||
title=sprintf("Heat normalized time"),
|
||||
subtitle=input_file) +
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Center the title
|
||||
#theme(plot.title = element_text(hjust = 0.5)) +
|
||||
|
||||
# Black and white mode (useful for printing)
|
||||
#theme_bw() +
|
||||
|
||||
# Add the maximum allowed error lines
|
||||
geom_hline(yintercept=c(-0.01, 0.01),
|
||||
linetype="dashed", color="red") +
|
||||
|
||||
# Draw boxplots
|
||||
p = ggplot(df, aes(x=cbs, y=normalized.time)) +
|
||||
geom_boxplot() +
|
||||
|
||||
#scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) +
|
||||
|
||||
geom_hline(yintercept=c(-0.01, 0.01), linetype="dashed", color="red") +
|
||||
theme_bw() +
|
||||
|
||||
theme(plot.subtitle=element_text(size=8)) +
|
||||
|
||||
theme(legend.position = c(0.85, 0.85)) #+
|
||||
|
||||
|
||||
|
||||
|
||||
# Render the plot
|
||||
print(p)
|
||||
|
||||
## Save the png image
|
||||
dev.off()
|
||||
#
|
||||
png("scatter.png", width=w*ppi, height=h*ppi, res=ppi)
|
||||
#
|
||||
## Create the plot with the normalized time vs nblocks
|
||||
p = ggplot(df, aes(x=cbs, y=time, linetype=rbs, group=rbs)) +
|
||||
|
||||
labs(x="cbs", y="Time (s)",
|
||||
title=sprintf("Heat granularity"),
|
||||
labs(y="Normalized time",
|
||||
title="Heat granularity: normalized time",
|
||||
subtitle=input_file) +
|
||||
theme_bw() +
|
||||
theme(plot.subtitle=element_text(size=8)) +
|
||||
theme(legend.position = c(0.5, 0.88)) +
|
||||
theme(plot.subtitle=element_text(size=8))
|
||||
|
||||
ggsave("normalized.time.png", plot=p, width=w, height=h, dpi=dpi)
|
||||
ggsave("normalized.time.pdf", plot=p, width=w, height=h, dpi=dpi)
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
p = ggplot(df, aes(x=cbs, y=time)) +
|
||||
geom_point(shape=21, size=3) +
|
||||
geom_line(aes(y=mtime)) +
|
||||
#scale_x_continuous(trans=log2_trans()) +
|
||||
scale_y_continuous(trans=log2_trans())
|
||||
|
||||
# Render the plot
|
||||
print(p)
|
||||
|
||||
# Save the png image
|
||||
dev.off()
|
||||
|
||||
|
||||
png("heatmap.png", width=w*ppi, height=h*ppi, res=ppi)
|
||||
#
|
||||
## Create the plot with the normalized time vs nblocks
|
||||
p = ggplot(df, aes(x=cbs, y=rbs, fill=logmtime)) +
|
||||
geom_raster() +
|
||||
scale_fill_gradient(high="black", low="white") +
|
||||
coord_fixed() +
|
||||
geom_line(aes(y=median.time, group=0)) +
|
||||
theme_bw() +
|
||||
theme(plot.subtitle=element_text(size=8)) +
|
||||
labs(x="cbs", y="rbs",
|
||||
title=sprintf("Heat granularity"),
|
||||
subtitle=input_file)
|
||||
labs(y="Time (s)", title="Heat granularity: time",
|
||||
subtitle=input_file) +
|
||||
theme(plot.subtitle=element_text(size=8))
|
||||
|
||||
# Render the plot
|
||||
print(p)
|
||||
|
||||
# Save the png image
|
||||
dev.off()
|
||||
ggsave("time.png", plot=p, width=w, height=h, dpi=dpi)
|
||||
ggsave("time.pdf", plot=p, width=w, height=h, dpi=dpi)
|
||||
|
Loading…
Reference in New Issue
Block a user