Skip to content

Commit

Permalink
Merge pull request #147 from albhasan/ggplot2_142
Browse files Browse the repository at this point in the history
Closes #142 I'm going to go ahead and merge this, its just fixing the language in the ggplot2 lesson
  • Loading branch information
kristi-sara authored Oct 18, 2024
2 parents 2379db6 + dbe9654 commit 3a09f64
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions episodes/07-plot-ggplot2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ library(dplyr)
```

Plotting our data is one of the best ways to quickly explore it and the various
relationships between variables. There are three main plotting systems in R, the
[base plotting system](https://www.statmethods.net/graphs/), the
relationships between variables. There are three main plotting systems in R,
the [base plotting system](https://www.statmethods.net/graphs/), the
[lattice](https://www.statmethods.net/advgraphs/trellis.html) package, and the
[ggplot2](https://www.statmethods.net/advgraphs/ggplot2.html) package. Today and
tomorrow we'll be learning about the ggplot2 package, because it is the most
effective for creating publication quality graphics. In this episode, we will
introduce the key features of a ggplot and make a few example plots. We will
expand on these concepts and see how they apply to geospatial data types when we
start working with geospatial data in the [R for Raster and Vector
[ggplot2](https://www.statmethods.net/advgraphs/ggplot2.html) package. Today
and tomorrow we'll be learning about the ggplot2 package, because it is one of
the most popular for creating publication quality graphics. In this episode, we
will introduce the key features of a ggplot and make a few example plots. We
will expand on these concepts and see how they apply to geospatial data types
when we start working with geospatial data in the [R for Raster and Vector
Data](https://datacarpentry.org/r-raster-vector-geospatial/) lesson.

::::::::::::::::::::::::::::::::::::::: instructor

- This episode introduces `geom_col` and `geom_histogram`. These geoms are used
in the rest of the workshop, along with geoms specifically for geospatial
in the rest of the workshop, along with geoms specifically for geospatial
data.
- Emphasize that we will go much deeper into visualization and creating
publication-quality graphics later in the workshop.
Expand Down Expand Up @@ -73,7 +73,7 @@ for histograms.

```{r lifeExp-vs-gdpPercap-scatter, fig.cap="Histogram of life expectancy by country showing bimodal distribution with modes at 45 and 75", message=FALSE}
library("ggplot2")
ggplot(data = gapminder, aes(x = lifeExp)) +
ggplot(data = gapminder, aes(x = lifeExp)) +
geom_histogram()
```

Expand All @@ -89,7 +89,7 @@ tells `ggplot` we want to visually represent the
distribution of one variable (in our case "lifeExp"):

```{r lifeExp-vs-gdpPercap-scatter2, fig.cap="Histogram of life expectancy by country showing bimodal distribution with modes at 45 and 75"}
ggplot(data = gapminder, aes(x = lifeExp)) +
ggplot(data = gapminder, aes(x = lifeExp)) +
geom_histogram()
```

Expand All @@ -106,7 +106,7 @@ expectancy:
## Solution to challenge 1

```{r ch1-sol}
ggplot(data = gapminder, aes(x = gdpPercap)) +
ggplot(data = gapminder, aes(x = gdpPercap)) +
geom_histogram()
```

Expand All @@ -131,7 +131,7 @@ We will plot countries on the x-axis (listed in alphabetic order
by default) and gdp per capita on the y-axis.

```{r hist-subset-gapminder, fig.cap="Barplot of GDP per capita. Country names on x-axis overlap and are not readable"}
ggplot(data = gapminder_small, aes(x = country, y = gdpPercap)) +
ggplot(data = gapminder_small, aes(x = country, y = gdpPercap)) +
geom_col()
```

Expand All @@ -140,7 +140,7 @@ x-axis labels. A quick fix to this is the add the `coord_flip()`
function to the end of our plot code.

```{r hist-subset-gapminder-flipped, fig.cap="Barplot showing GDP per capita. Country names on the y-axis are readable"}
ggplot(data = gapminder_small, aes(x = country, y = gdpPercap)) +
ggplot(data = gapminder_small, aes(x = country, y = gdpPercap)) +
geom_col() +
coord_flip()
```
Expand Down Expand Up @@ -185,10 +185,10 @@ The default behavior for `postion` in `geom_col()`
is "stack".

```{r gpd-per-cap}
ggplot(gapminder_small_2,
aes(x = country, y = gdpPercap,
ggplot(gapminder_small_2,
aes(x = country, y = gdpPercap,
fill = as.factor(year))) +
geom_col(position = "dodge") +
geom_col(position = "dodge") +
coord_flip()
```

Expand Down

0 comments on commit 3a09f64

Please sign in to comment.