Daniel Vaulot
2021-10-12
Source: Michael Friendly - http://datavis.ca/courses/RGraphics/
@allison_horst
library("readxl") # Import the data from Excel filelibrary("dplyr") # filter and reformat data frameslibrary("ggplot2") # graphics
samples <- readxl::read_excel("data/CARBOM data.xlsx", sheet = "Samples_boat") %>% tidyr::fill(station)
sample number | transect | station | date | time | depth | level | latitude | longitude | picoeuks | nanoeuks | phosphates | nitrates | temperature | salinity |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
10 | 1 | 81 | 2013-11-13 | 1899-12-31 01:00:00 | 140 | Deep | -27.42 | -44.72 | 3278 | 1232 | 0.20 | 0.26 | 17.3 | 35.9 |
11 | 1 | 85 | 2013-11-13 | 1899-12-31 13:30:00 | 110 | Deep | -26.80 | -45.30 | 16312 | 1615 | 0.29 | 0.22 | 21.3 | 36.5 |
120 | 2 | 96 | 2013-11-18 | 1899-12-31 23:50:00 | 5 | Surf | -27.39 | -47.82 | 1150 | 75 | 0.43 | 0.19 | 23.1 | 33.5 |
121 | 2 | 96 | 2013-11-18 | 1899-12-31 23:50:00 | 30 | Deep | -27.39 | -47.82 | 1737 | 218 | 0.43 | 0.23 | 22.6 | 33.7 |
122 | 2 | 96 | 2013-11-18 | 1899-12-31 23:50:00 | 50 | Deep | -27.39 | -47.82 | 853 | 234 | 0.56 | 0.21 | 20.3 | 35.9 |
125 | 2 | 98 | 2013-11-18 | 1899-12-31 05:00:00 | 5 | Surf | -27.59 | -47.39 | 3086 | 1300 | 0.29 | 0.25 | 23.1 | 35.7 |
126 | 2 | 98 | 2013-11-18 | 1899-12-31 05:00:00 | 50 | Deep | -27.59 | -47.39 | 1217 | 782 | 0.25 | 0.20 | 23.7 | 37.2 |
127 | 2 | 98 | 2013-11-18 | 1899-12-31 05:00:00 | 85 | Deep | -27.59 | -47.39 | 3420 | 226 | 0.25 | 0.47 | 22.9 | 37.0 |
13 | 1 | 86 | 2013-11-13 | 1899-12-31 17:00:00 | 105 | Deep | -26.33 | -45.41 | 6366 | 1007 | 0.34 | 0.15 | 20.9 | 36.3 |
140 | 2 | 101 | 2013-11-18 | 1899-12-31 12:00:00 | 5 | Surf | -27.79 | -46.96 | 500 | 366 | 0.29 | 0.14 | 23.5 | 36.5 |
ggplot(data=samples) + geom_point(mapping = aes(x=phosphates, y=nitrates))
ggplot(data=samples) + geom_point(mapping = aes(x=phosphates, y=nitrates))
Every graph can be described as a combination of independent building blocks:
Syntax
ggplot(data=samples) + geom_point(mapping = aes(x=phosphates, y=nitrates))
Alternatively
ggplot(data=samples, mapping = aes(x=phosphates, y=nitrates)) + geom_point()
Alternatively
ggplot(samples, aes(x=phosphates, y=nitrates)) + geom_point()
ggplot(samples, aes(x=phosphates, y=nitrates))
ggplot(samples, aes(x=phosphates, y=nitrates)) + geom_point(size=5)
ggplot(samples, aes(x=phosphates, y=nitrates, color=level)) + geom_point(size=5)
ggplot(samples, aes(x=phosphates, y=nitrates, color=depth)) + geom_point(size=5)
ggplot(samples, aes(x=phosphates, y=nitrates, color=depth, shape=transect)) + geom_point(size=5)
Error: A continuous variable can not be mapped to shape
ggplot(samples, aes(x=phosphates, y=nitrates, color=depth, shape=as.character(transect))) + geom_point(size=5)
ggplot(samples, aes(x=phosphates, y=nitrates)) + geom_point() + facet_wrap(~ level)
ggplot(samples, aes(x=phosphates, y=nitrates, color=level)) + geom_point(size=5) + geom_smooth(mapping = aes(x=phosphates, y=nitrates), method="lm")
ggplot(samples, aes(x=phosphates, y=nitrates)) + geom_point(aes(color=level), size=5) + geom_smooth(mapping = aes(x=phosphates, y=nitrates), method="lm")
ggplot(samples) + geom_point(mapping = aes(x=phosphates, y=nitrates, color=level), size=5) + geom_smooth(mapping = aes(x=phosphates, y=nitrates), method="lm") + xlab("Phosphates") + ylab("Nitrates") + ggtitle("CARBOM cruise")
Package tmaptools : https://github.com/mtennekes/tmaptools
palette_explorer()
Package paletteer : https://github.com/EmilHvitfeldt/paletteer
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |