Skip to content

Commit 9f5ee97

Browse files
committed
Updated plots
- use geom_violin under boxplot - add points to lines for specific cultivar - change figure title
1 parent a4e635a commit 9f5ee97

1 file changed

Lines changed: 36 additions & 24 deletions

File tree

  • experiment-trait-data-visualizer

experiment-trait-data-visualizer/app.R

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,41 @@ render_trait_plot <- function(season_name, input, output, full_cache_data) {
103103
plot_data <- selected_season_data[[ 'trait_data' ]][[ selected_variable ]][[ 'traits' ]]
104104
data_max <- max(plot_data[[ 'mean' ]])
105105

106-
title <- selected_variable
107106
units <- selected_season_data[[ 'trait_data' ]][[ selected_variable ]][[ 'units' ]]
108-
if (units != '')
109-
title <- paste0(selected_variable, ' (', units, ')')
110-
111-
ggplot(plot_data, aes(as.Date(date), mean)) +
112-
geom_boxplot(aes(group = cut_width(as.Date(date), 1)), outlier.alpha = 0.1) +
107+
title <- ifelse(units == '', selected_variable, paste0(selected_variable, ' (', units, ')'))
113108

114-
{
115-
if (selected_cultivar != 'None') {
116-
title <- paste0(title, ' for ', selected_cultivar)
117-
geom_line(data = subset(plot_data, cultivar_name == selected_cultivar),
118-
size = 0.5, color = '#00C49F', aes(x = as.Date(date), y = mean, group = site_id))
119-
}
120-
} +
121-
122-
labs(
123-
title = paste0(title, '\n'),
124-
x = "Observation Dates",
125-
y = units
126-
) +
109+
trait_plot <- ggplot() +
110+
geom_violin(data = plot_data, scale = 'width', width = 0.75,
111+
aes(x = as.Date(date), y = mean,
112+
group = as.Date(date))) +
113+
geom_boxplot(data = plot_data,
114+
aes(x = as.Date(date), y = mean,
115+
group = as.Date(date)),
116+
outlier.alpha = 0.25, width = 0.2)
117+
# geom_point(data = plot_data,
118+
# aes(x = as.Date(date), y = mean),
119+
# alpha = 0.1, size = 0.1, position = position_jitter(width = 0.1))
120+
121+
if (selected_cultivar != 'None') {
122+
title <- paste0(title, '\nCultivar ', selected_cultivar, ' in red')
123+
trait_plot <- trait_plot +
124+
geom_point(data = subset(plot_data, cultivar_name == selected_cultivar),
125+
color = 'red', aes(x = as.Date(date), y = mean, group = site_id)) +
126+
geom_line(data = subset(plot_data, cultivar_name == selected_cultivar),
127+
size = 0.5, color = 'red', aes(x = as.Date(date), y = mean, group = site_id))
128+
}
127129

128-
theme(text = element_text(size = 20), axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none") +
129-
xlim(as.Date(selected_season_data[[ 'start_date' ]]), as.Date(selected_season_data[[ 'end_date' ]])) +
130-
ylim(0, data_max)
130+
trait_plot +
131+
labs(
132+
title = paste0(title, '\n'),
133+
x = "Date",
134+
y = units
135+
) +
136+
137+
theme_bw() +
138+
theme(text = element_text(size = 20), axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none") +
139+
xlim(as.Date(selected_season_data[[ 'start_date' ]]), as.Date(selected_season_data[[ 'end_date' ]])) +
140+
ylim(0, data_max)
131141
})
132142
}
133143

@@ -261,8 +271,10 @@ render_season_output <- function(season_name, input, output, full_cache_data) {
261271
server <- function(input, output) {
262272

263273
# load 'full_cache_data' object from cache file
264-
if (!file.exists('cache.RData'))
274+
if (!file.exists('cache.RData')){
265275
source('cache-refresh.R')
276+
}
277+
266278
load('cache.RData')
267279

268280
# render UI for all available seasons
@@ -275,4 +287,4 @@ server <- function(input, output) {
275287
lapply(names(full_cache_data), render_season_output, input, output, full_cache_data)
276288
}
277289

278-
shinyApp(ui = ui, server = server)
290+
shinyApp(ui = ui, server = server)

0 commit comments

Comments
 (0)