Skip to content

Commit d11adbf

Browse files
committed
ggplot solutions
1 parent e7bd84b commit d11adbf

26 files changed

Lines changed: 2387 additions & 287 deletions

14-ggplot.Rmd

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,128 @@ Create the following plots:
198198
3.1 a horizontal line indicating critical oxygen concentrations of 4 mg/l
199199
3.2 color the line based on the temperature values. Use an appropriate color scale.
200200

201+
202+
## Solution
203+
204+
<details>
205+
<summary>Click for Answer</summary>
206+
207+
208+
209+
210+
### Boxplots of the Aranae Species per crop type.
211+
212+
```{r}
213+
library(ggplot2)
214+
215+
cropspecies = read.csv("data/crop_species.csv")
216+
217+
ggplot(data = cropspecies,
218+
mapping = aes(x = Croptype,
219+
y = AraSpec,
220+
fill = Croptype))+
221+
geom_boxplot()+
222+
scale_fill_manual(values = c("red", "blue", "green", "yellow", "black"))
223+
224+
225+
## Define colors beforehand
226+
sc = c("KE" = "#66CD00",
227+
"ZR" = "#FFB90F",
228+
"SM" = "#FF7F00",
229+
"WR" = "yellow",
230+
"WW" = "black")
231+
232+
233+
ggplot(data = cropspecies,
234+
mapping = aes(x = Croptype,
235+
y = AraSpec,
236+
fill = Croptype))+
237+
geom_boxplot()+
238+
scale_fill_manual(values = sc)
239+
240+
```
241+
242+
243+
244+
245+
246+
247+
### Plot the Carabidae Individuums vs. the Carabidae Species and color the points based on the crop on the field.
248+
249+
250+
```{r}
251+
ggplot(cropspecies, aes(x = CaraInd,
252+
y = CaraSpec))+
253+
geom_point()+
254+
geom_smooth(method = "lm")+
255+
geom_point(aes(color = Croptype))
256+
```
257+
258+
259+
### Create a map of the trees in Münster + Heatmap
260+
261+
262+
```{r}
263+
trees = read.csv("data/muenster_trees.csv")
264+
265+
266+
ggplot(trees, aes(x = X, y = Y))+
267+
geom_point(alpha = 0.5)
268+
269+
ggplot(trees, aes(x = X, y = Y))+
270+
geom_bin_2d(bins = 40)
271+
272+
ggplot(trees, aes(x = X, y = Y))+
273+
geom_hex()+
274+
theme_bw()
275+
```
276+
277+
278+
279+
280+
### A bar plot (geom_col) of the Top 10 districts of Münster with the most trees.
281+
282+
```{r}
283+
districts = table(trees$district)
284+
districts = as.data.frame(districts)
285+
286+
287+
districts = districts[order(districts$Freq, decreasing = TRUE),]
288+
districts_t10 = districts[seq(10),]
289+
290+
ggplot(districts_t10, aes(y = reorder(Var1, Freq), x = Freq))+
291+
geom_col()
292+
```
293+
294+
295+
296+
297+
298+
299+
300+
### A time series of the oxygen content in the Aasee
301+
302+
303+
```{r}
304+
library(lubridate)
305+
306+
aasee = read.csv("data/2021-07_aasee.csv")
307+
aasee$Datum = lubridate::ymd_hm(aasee$Datum)
308+
309+
310+
ggplot(aasee, aes(x = Datum, y = Sauerstoffgehalt, color = Wassertemperatur))+
311+
geom_line()+
312+
geom_abline(slope = 0, intercept = 1, color = "red")+
313+
scale_x_datetime(name = "Datum")+
314+
annotate(geom = "text",
315+
label = "Text",
316+
x = lubridate::ymd_hm("2021-07-01 02:00"), y = 4)+
317+
scale_color_gradientn(colors = viridis::inferno(50))
318+
```
319+
320+
321+
322+
323+
324+
</details>
325+

docs/404.html

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
77
<title>Page not found | Analysis of Ecological Data with R</title>
88
<meta name="description" content="This is currently a slide collection for the ILOEK Course “Analysis of ecological data in R” but could eventually turn into a more comprehensive ressource collection." />
9-
<meta name="generator" content="bookdown 0.26 and GitBook 2.6.7" />
9+
<meta name="generator" content="bookdown 0.27 and GitBook 2.6.7" />
1010

1111
<meta property="og:title" content="Page not found | Analysis of Ecological Data with R" />
1212
<meta property="og:type" content="book" />
@@ -51,22 +51,6 @@
5151
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
5252
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
5353
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
54-
<script src="libs/htmlwidgets-1.5.4/htmlwidgets.js"></script>
55-
<link href="libs/leaflet-1.3.1/leaflet.css" rel="stylesheet" />
56-
<script src="libs/leaflet-1.3.1/leaflet.js"></script>
57-
<link href="libs/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
58-
<script src="libs/proj4-2.6.2/proj4.min.js"></script>
59-
<script src="libs/Proj4Leaflet-1.0.1/proj4leaflet.js"></script>
60-
<link href="libs/rstudio_leaflet-1.3.1/rstudio_leaflet.css" rel="stylesheet" />
61-
<script src="libs/leaflet-binding-2.1.1/leaflet.js"></script>
62-
<script src="libs/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js"></script>
63-
<script src="libs/leaflet-providers-plugin-2.1.1/leaflet-providers-plugin.js"></script>
64-
<link href="libs/HomeButton-0.0.1/home-button.css" rel="stylesheet" />
65-
<script src="libs/HomeButton-0.0.1/home-button.js"></script>
66-
<script src="libs/HomeButton-0.0.1/easy-button-src.min.js"></script>
67-
<script src="libs/clipboard-0.0.1/setClipboardText.js"></script>
68-
<link href="libs/mapviewCSS-0.0.1/mapview-popup.css" rel="stylesheet" />
69-
<link href="libs/mapviewCSS-0.0.1/mapview.css" rel="stylesheet" />
7054

7155

7256
<style type="text/css">
@@ -107,7 +91,7 @@
10791
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
10892
code span.at { color: #7d9029; } /* Attribute */
10993
code span.bn { color: #40a070; } /* BaseN */
110-
code span.bu { } /* BuiltIn */
94+
code span.bu { color: #008000; } /* BuiltIn */
11195
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
11296
code span.ch { color: #4070a0; } /* Char */
11397
code span.cn { color: #880000; } /* Constant */
@@ -120,7 +104,7 @@
120104
code span.ex { } /* Extension */
121105
code span.fl { color: #40a070; } /* Float */
122106
code span.fu { color: #06287e; } /* Function */
123-
code span.im { } /* Import */
107+
code span.im { color: #008000; font-weight: bold; } /* Import */
124108
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
125109
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
126110
code span.op { color: #666666; } /* Operator */
@@ -134,28 +118,6 @@
134118
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
135119
</style>
136120

137-
<style type="text/css">
138-
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
139-
div.csl-bib-body { }
140-
div.csl-entry {
141-
clear: both;
142-
}
143-
.hanging div.csl-entry {
144-
margin-left:2em;
145-
text-indent:-2em;
146-
}
147-
div.csl-left-margin {
148-
min-width:2em;
149-
float:left;
150-
}
151-
div.csl-right-inline {
152-
margin-left:2em;
153-
padding-left:1em;
154-
}
155-
div.csl-indent {
156-
margin-left: 2em;
157-
}
158-
</style>
159121

160122
<link rel="stylesheet" href="style.css" type="text/css" />
161123
</head>
@@ -277,20 +239,6 @@ <h1>Page not found</h1>
277239
});
278240
</script>
279241

280-
<!-- dynamically load mathjax for compatibility with self-contained -->
281-
<script>
282-
(function () {
283-
var script = document.createElement("script");
284-
script.type = "text/javascript";
285-
var src = "true";
286-
if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
287-
if (location.protocol !== "file:")
288-
if (/^https?:/.test(src))
289-
src = src.replace(/^https?:/, '');
290-
script.src = src;
291-
document.getElementsByTagName("head")[0].appendChild(script);
292-
})();
293-
</script>
294242
</body>
295243

296244
</html>

0 commit comments

Comments
 (0)