Skip to content

Commit

Permalink
aggregated axis labelling into single line per plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrin Leinweber committed Dec 7, 2014
1 parent b102212 commit 59e317a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions summarize-flattr-reports.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export_csv(per_month, "flattr-revenue-months.csv")

# themeing function for following plots
set_advanced_theme <- function(){
theme(axis.text = element_text(size = N_months),
theme(plot.title = element_text(size = N_months * 1.4),
axis.text = element_text(size = N_months),
axis.text.x = element_text(angle = 30, hjust = 1), # hjust prevents overlap with panel; learned from http://stackoverflow.com/a/1331400
axis.title.x = element_blank(), # remove axis title, because months labels are unambiguous already
axis.title.y = element_text(size = N_months * 1.2),
legend.title = element_text(size = N_months / 1.4),
panel.grid.major = element_line(color = "lightgrey", size = N_months/40),
panel.grid.minor.x = element_blank(),
panel.background = element_rect(fill = "white"),
Expand All @@ -109,7 +111,7 @@ flattr_plot <- ggplot(data = raw, mapping = aes(x = period, y = EUR_per_click,
size = raw$revenue, # points sized according to revenue of that thing in that month => bubble plot
colour = factor(title))) +
geom_jitter() + # same as geom_point(position = "jitter"); spreads data points randomly around true x value bit; day-exact resolution not (yet) possible
ylab("EUR per Flattr") +
labs(list(title = "Flattr Revenue Development Per Click\n", x = NULL, y = "EUR per Flattr\n")) + # learned from http://docs.ggplot2.org/current/labs.html
labs(color = "Flattred Things", size = "EUR per Thing") + # set legend titles; arguments have to be same as in ggplot() call
stat_smooth(mapping = aes(best_thing$period, best_thing$EUR_per_click, size = best_thing$all_revenue),
data = best_thing, method = "auto", show_guide = FALSE, size = N_months/20,
Expand All @@ -129,9 +131,8 @@ export_plot(flattr_plot, "flattr-revenue-clicks.png")
# revenue per month and thing
monthly_advanced_plot <- ggplot(per_month_and_thing, aes(x = period, y = all_revenue, fill = factor(title))) +
geom_bar(stat = "identity") +
ylab("EUR received") +
xlab(NULL) + # learned from http://www.talkstats.com/showthread.php/54720-ggplot2-ylab-and-xlab-hell?s=445d87d53add5909ac683c187166c9fd&p=154224&viewfull=1#post154224
labs(fill = "Flattr-Things") + scale_y_continuous(limits = c(0,max(per_month_and_thing$all_revenue) * 1.1), expand = c(0, 0)) +
labs(list(title = "Flattr Revenue Development of Things\n", x = NULL, y = "EUR received\n")) +
labs(fill = "Flattred Things") + scale_y_continuous(limits = c(0,max(per_month_and_thing$all_revenue) * 1.1), expand = c(0, 0)) +
scale_x_date(expand = c(0, 0)) +
guides(fill = guide_legend(reverse = TRUE)) + # align legend order with fill order of bars in plot; learned from http://www.cookbook-r.com/Graphs/Legends_%28ggplot2%29/#kinds-of-scales
set_advanced_theme()
Expand All @@ -140,7 +141,7 @@ export_plot(monthly_advanced_plot, "flattr-revenue-months.png")
# total revenue per month with trend
monthly_simple_plot <- ggplot(data = per_month, aes(x = period, y = all_revenue)) +
geom_bar(stat = "identity", group = 1, fill = "#ED8C3B") +
ylab("EUR received") + xlab(NULL) +
labs(list(title = "Flattr Revenue Development\n", x = NULL, y = "EUR received\n")) +
stat_smooth(data = per_month, method = "auto", color = "#80B04A", size = N_months/5) + # fit trend plus confidence interval
scale_y_continuous(limits = c(0,max(per_month$all_revenue) * 1.1), # omit negative y-values & limit positive y-axis to 10% overhead over maximum value
expand = c(0, 0)) + set_advanced_theme()
Expand All @@ -159,8 +160,8 @@ per_month_and_domain <- per_month_and_domain[order(per_month_and_domain$domain),
export_csv(per_month_and_domain, "flattr-revenue-clicks-domain.csv")

monthly_domain_plot <- ggplot(per_month_and_domain, aes(x = period, y = all_revenue, fill = factor(domain))) +
geom_bar(stat = "identity") + ylab("EUR received") +
xlab(NULL) + # learned from http://www.talkstats.com/showthread.php/54720-ggplot2-ylab-and-xlab-hell?s=445d87d53add5909ac683c187166c9fd&p=154224&viewfull=1#post154224
geom_bar(stat = "identity") +
labs(list(title = "Revenue Development by Button Locations\n", x = NULL, y = "EUR received\n")) +
labs(fill = "Domains") +
scale_y_continuous(limits = c(0,max(per_month_and_domain$all_revenue) * 1.1), expand = c(0, 0),
breaks = seq(0, round(max(per_month$all_revenue) * 1.1),
Expand Down

0 comments on commit 59e317a

Please sign in to comment.