## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

ggplot- Schichten

Ästestetisches Mapping

Hier soll gezeigt werden, wie man aussagekräftige Grafiken erstellen kann. Dabei wird das Package ggplot2 verwendet werden, die im tidyverse-Package enthalten ist.

###
# Kapitel 9: Aestetic-Layer
#
#
# DS: mpg
# Erster plott mit classe farblich hinterlegt
ggplot(data = mpg,
       aes(x = displ,
           y = hwy,
           color = class)) +
  geom_point()

# gleiche grafik mit unterschiedlichen Formen an Punkten
ggplot(data = mpg,
       aes(x = displ,
           y = hwy,
           shape = class)) +
  geom_point()
## Warning: The shape palette can deal with a maximum of 6 discrete values because more
## than 6 becomes difficult to discriminate
## ℹ you have requested 7 values. Consider specifying shapes manually if you need
##   that many have them.
## Warning: Removed 62 rows containing missing values (`geom_point()`).

Mit der Anweisung shape können nur 5 unterschiedliche Formen erzeugt werden. daher werden die Werte der Klasse suv nicht angezeigt.

#gleicher Grafiktyp. 
# 1. Mit unterschiedlich großen Punkten
ggplot(data = mpg,
       aes(x = displ,
           y = hwy,
           size = class)) +
  geom_point()
## Warning: Using size for a discrete variable is not advised.

# 2. Unterschiedliche "durchsichtigkeit"
ggplot(data = mpg,
       aes(x= displ,
           y = hwy,
           alpha = class )) +
  geom_point()
## Warning: Using alpha for a discrete variable is not advised.

## Übungsbeispiele 1. Erzeuge ein Punktdiagram (Scatterplot) mit x= displ und y = hwy, in dem die Punkte rosarot und die Form ausgefüllte Dreiecke sind

ggplot(data = mpg,
       aes(x = displ,
           y = hwy)
       ) +
  geom_point(color = "pink",
             shape = 17)

## Beispiel 4

ggplot(data = mpg,
       aes(x= displ,
           y = hwy,
           color = displ >= 5 )) +
  geom_point()