Skip to content

Commit beff784

Browse files
Merge pull request #24 from KonScience/develop
optimise plots
2 parents b93e8dd + 0bbee98 commit beff784

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

summarize-flattr-reports.R

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,18 @@ flattr_plot <- ggplot(data = raw,
9999
size = raw$revenue, # points sized according to revenue of that thing in that month => bubble plot
100100
colour = factor(title))) +
101101
geom_jitter() + # same as geom_point(position = "jitter"); spreads data points randomly around true x value bit; day-exact resolution not (yet) possible
102-
labs(title = "Development of Flattr Revenue per Click",
103-
x = NULL, y = expression("EUR per Flattr (extremes omitted)")) + # learned from http://docs.ggplot2.org/current/labs.html
104-
stat_smooth(mapping = aes(best_thing$period,
105-
best_thing$EUR_per_click,
102+
labs(title = "Development of Flattr Revenue per Click", # learned from http://docs.ggplot2.org/current/labs.html
103+
x = NULL,
104+
y = expression("EUR per Flattr (extremes omitted)"),
105+
colour = "Thing",
106+
size = "Total revenue of Thing") +
107+
stat_smooth(mapping = aes(x = best_thing$period,
108+
y = best_thing$EUR_per_click,
106109
size = best_thing$all_revenue),
107110
data = best_thing,
108111
method = "auto",
109112
show_guide = FALSE,
110-
size = N_months / 20,
113+
size = N_things / N_months,
111114
se = FALSE, # confidence interval indicator
112115
linetype = "dashed") + # learned from http://sape.inf.usi.ch/quick-reference/ggplot2/linetype
113116
stat_smooth(aes(group = 1), # plots trendline over all values; otherwise: one for each thing; learned from http://stackoverflow.com/a/12810890
@@ -118,18 +121,18 @@ flattr_plot <- ggplot(data = raw,
118121
size = N_months / 20) +
119122
scale_y_continuous(limits = c(0, mean(raw$EUR_per_click) * 5), # omit extreme y-values; learned from http://stackoverflow.com/a/26558070
120123
expand = c(0, 0)) +
121-
theme(legend.position = "none") +
122-
theme_classic(base_size = sqrt(N_things + N_months))
124+
theme_classic() +
125+
theme(legend.position = "none")
123126
flattr_plot
124-
ggsave("flattr-revenue-clicks.png", height = N_things/3, width = N_months/1.5)
127+
ggsave("flattr-revenue-clicks.png")
125128

126129
# revenue per month and thing
127130
monthly_advanced_plot <- ggplot(per_month_and_thing, aes(period, all_revenue, fill = factor(title))) +
128131
geom_bar(stat = "identity") +
129-
labs(title = "Development of Flattr Revenue by Things", x = NULL, y = "EUR received") +
132+
labs(title = "Development of Flattr Revenue by Things", x = NULL, y = "EUR received", fill = "Thing") +
130133
scale_y_continuous(limits = c(0, max(per_month$all_revenue) * 1.1), expand = c(0, 0)) +
131134
scale_x_date(expand = c(0, 0)) +
132-
theme(legend.position = "none") +
135+
guides(fill = guide_legend(reverse = TRUE)) +
133136
theme_classic(base_size = (N_things + N_months) / 5)
134137
monthly_advanced_plot
135138
ggsave("flattr-revenue-months.png", height = N_things/3, width = N_months/1.5)
@@ -138,10 +141,10 @@ ggsave("flattr-revenue-months.png", height = N_things/3, width = N_months/1.5)
138141
monthly_simple_plot <- ggplot(per_month, aes(x = period, y = all_revenue)) +
139142
geom_bar(stat = "identity", group = 1, fill = "#ED8C3B") +
140143
labs(title = "Development of Flattr Revenue", x = NULL, y = "EUR received") +
141-
stat_smooth(data = per_month, method = "auto", color = "#80B04A", size = N_months/5) + # fit trend plus confidence interval
144+
stat_smooth(data = per_month, method = "auto", color = "#80B04A", size = N_things / N_months) + # fit trend plus confidence interval
142145
scale_y_continuous(limits = c(0, max(per_month$all_revenue) * 1.1), expand = c(0, 0)) +
143146
scale_x_date(expand = c(0, 0)) +
144-
theme_classic(base_size = (N_things + N_months) / 10)
147+
theme_classic(base_size = sqrt(N_things + N_months))
145148
monthly_simple_plot
146149
ggsave("flattr-revenue-months-summarized.png")
147150

@@ -168,23 +171,24 @@ per_month_and_domain <- ddply(raw,
168171
monthly_domain_plot <- ggplot(per_month_and_domain, aes(period, all_revenue, fill = factor(domain))) +
169172
geom_bar(stat = "identity") +
170173
labs(title = "Development of Flattr Revenue by Button Locations", x = NULL, y = "EUR received", fill = "Domains") +
171-
guides(fill = guide_legend(reverse = TRUE)) +
174+
guides(fill = guide_legend(reverse = TRUE, keywidth = 0.5, keyheight = 0.5)) +
172175
scale_x_date(expand = c(0,0)) +
173-
scale_y_continuous(limits = c(0, max(per_month$all_revenue) * 1.1), expand = c(0, 0)) +
176+
scale_y_continuous(limits = c(0, max(per_month$all_revenue)), expand = c(0, 0)) +
174177
scale_fill_brewer(type = "qual") +
175-
theme_classic(base_size = (N_things + N_months) / 10)
178+
theme_classic(base_size = sqrt(N_things + N_months))
176179
monthly_domain_plot
177180
ggsave("flattr-revenue-months-domain.png")
178181

179182
monthly_domain_plot_fractions <- ggplot(per_month_and_domain, aes(period, all_revenue, fill = factor(domain))) +
180183
geom_bar(position = "fill", stat = "identity") +
184+
coord_flip() +
181185
labs(title = "Fractions of Flattr Revenue by Button Locations",
182186
x = NULL, y = NULL, fill = "Domains") +
183-
guides(fill = guide_legend(reverse = TRUE)) +
184-
scale_x_date(expand = c(0,0)) +
187+
guides(fill = guide_legend(reverse = TRUE, keywidth = 0.5, keyheight = 0.5)) +
188+
scale_x_date(expand = c(0,0), breaks = "3 month") +
185189
scale_y_continuous(expand = c(0, 0)) +
186190
scale_fill_brewer(type = "qual") +
187-
theme_classic(base_size = (N_things + N_months) / 10)
191+
theme_classic(base_size = sqrt(N_things + N_months))
188192
monthly_domain_plot_fractions
189193
ggsave("flattr-revenue-months-domain-fractions.png")
190194

0 commit comments

Comments
 (0)