From de5d196258077b8393351300fefdf090d4a9f5ec Mon Sep 17 00:00:00 2001 From: Vojczech Date: Tue, 4 Jun 2019 09:52:05 +0200 Subject: [PATCH] hrbrthemes flavoured ggplot inspiration for hrbrthemes from this great blog chichacha.netlify.com implementation based on GH issue github.com/hrbrmstr/hrbrthemes/issues/19#issuecomment-353544955 --- server.R | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/server.R b/server.R index 6ee0d86..0dff15f 100644 --- a/server.R +++ b/server.R @@ -1,3 +1,4 @@ +# load packages library(shiny) library(shinythemes) library(readr) @@ -6,6 +7,13 @@ library(Rmisc) library(tools) library(gridExtra) library(grid) +library(showtext) +library(hrbrthemes) + +# download a webfont +font_add_google(name = "Roboto Condensed", family = "Roboto Condensed", + regular.wt = 400, bold.wt = 700) +showtext_auto() function(input, output) { @@ -156,8 +164,10 @@ function(input, output) { # {if (input$sensor == "lower" & input$average == TRUE) # annotate("text", x = as.POSIXct(input$date_range[1] + 0.5), y = temp_average_lower + 0.01, label = "lower sensor", size = 2) # } + - theme_bw() + - theme(axis.text.x = element_text(angle = 90, size = 10, colour = "black"), axis.text.y = element_text(size = 13, colour = "black"), axis.title = element_text(size = 14, face = "bold", colour = "black"), plot.title = element_text(size = 14, face = "bold", colour = "black"), plot.subtitle = element_text(colour = "black"), panel.grid.minor = element_blank(), legend.position = "top", legend.text = element_text(size = 11, colour = "black", face = "plain"), legend.title = element_text(size = 12, colour = "black", face = "bold"), legend.key.size = unit(3, 'lines'), legend.spacing.x = unit(0.3, 'cm'), legend.direction = "horizontal") + theme_ipsum_rc() + + theme(axis.text.x = element_text(angle = 90), + legend.position = "top", + legend.direction = "horizontal") } else if (input$plot_type == "moisture"){ # if moisture data are checked ggplot(data = dataset_temp_filtered, aes(y = temp, x = date_parsed)) + @@ -176,8 +186,10 @@ function(input, output) { scale_x_datetime(date_breaks = "1 year") } else {}} + labs(title = input$plot_title, subtitle = paste("mean moisture - ", round(moisture_average, digits = 1)), x = "date", y = "moisture") + - theme_bw() + - theme(axis.text.x = element_text(angle = 90, size = 10, colour = "black"), axis.text.y = element_text(size = 13, colour = "black"), axis.title = element_text(size = 14, face = "bold", colour = "black"), plot.title = element_text(size = 14, face = "bold", colour = "black"), plot.subtitle = element_text(colour = "black"), panel.grid.minor = element_blank(), legend.position = "top", legend.text = element_text(size = 11, colour = "black", face = "plain"), legend.title = element_text(size = 12, colour = "black", face = "bold"), legend.key.size = unit(3, 'lines'), legend.spacing.x = unit(0.3, 'cm'), legend.direction = "horizontal") + theme_ipsum_rc() + + theme(axis.text.x = element_text(angle = 90), + legend.position = "top", + legend.direction = "horizontal") } else { # if combined data are checked temp_plot <- ggplot(data = dataset_temp_filtered, aes(y = temp, x = date_parsed)) + @@ -196,8 +208,10 @@ function(input, output) { scale_x_datetime(date_breaks = "1 year") } else {}} + labs(subtitle = paste("mean upper sensor - ", round(temp_average_upper, digits = 1), "°C\n", "mean middle sensor - ", round(temp_average_middle, digits = 1), "°C\n", "mean lower sensor - ", round(temp_average_lower, digits = 1), "°C\n"), x = "date", y = "temperature [°C]") + - theme_bw() + - theme(axis.text.x = element_blank(), axis.text.y = element_text(size = 13, colour = "black"), axis.title.y = element_text(size = 14, face = "bold", colour = "black"), axis.title.x = element_blank(), plot.title = element_blank(), plot.subtitle = element_text(colour = "black"), panel.grid.minor = element_blank(), legend.position = "top", legend.text = element_text(size = 11, colour = "black", face = "plain"), legend.title = element_text(size = 12, colour = "black", face = "bold"), legend.key.size = unit(3, 'lines'), legend.spacing.x = unit(0.3, 'cm'), legend.direction = "horizontal") + theme_ipsum_rc() + + theme(axis.text.x = element_blank(), + legend.position = "top", + legend.direction = "horizontal") moist_plot <- ggplot(data = dataset_temp_filtered, aes(y = temp/100, x = date_parsed)) + geom_line(aes(colour = position), size = 1, alpha = 1, subset(dataset_temp_filtered, position == "moisture")) + scale_color_viridis_d(labels = "moisture") + # color in the case of discrete values @@ -214,8 +228,10 @@ function(input, output) { scale_x_datetime(date_breaks = "1 year") } else {}} + labs(subtitle = paste("mean moisture - ", round(moisture_average, digits = 1)), x = "date", y = "moisture (*100)") + - theme_bw() + - theme(axis.text.x = element_text(angle = 90, size = 10, colour = "black"), axis.text.y = element_text(size = 13, colour = "black"), axis.title = element_text(size = 14, face = "bold", colour = "black"), plot.title = element_blank(), plot.subtitle = element_text(colour = "black"), panel.grid.minor = element_blank(), legend.position = "none", legend.text = element_text(size = 11, colour = "black", face = "plain"), legend.title = element_blank(), legend.key.size = unit(3, 'lines'), legend.spacing.x = unit(0.3, 'cm'), legend.direction = "horizontal") + theme_ipsum_rc() + + theme(axis.text.x = element_text(angle = 90), + legend.position = "none", + legend.direction = "horizontal") plots_both <- grid.arrange(temp_plot, moist_plot, ncol = 1, top = textGrob(input$plot_title, gp = gpar(cex = 1.3, fontface = "bold", col = "black"), x = 0.08, y = 0.55)) } })