# ggplot2

\-- <https://github.com/GladB/ggplot_tutorial/blob/master/to_present.Rmd>

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiOnRn-ICC4wr9YLnw-%2F-LiOopyWGVG1Bioux0TU%2Fimg5.png?alt=media\&token=1aa1fe5f-5616-4587-a403-93f8ec5997ef)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(Sepal.Length, Petal.Length))+
 geom_point(aes(color=Sepal.Width))+
 geom_smooth(method="lm")+
 theme_bw()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiOnRn-ICC4wr9YLnw-%2F-LiOoxP-nmLSx5gqOciy%2Fimg2.png?alt=media\&token=7de7ac1f-faa5-4555-aac8-1fa1fa53cc6d)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
  geom_boxplot(width = 0.6, alpha=0.5)+
  geom_jitter(width=0.1, height=0)+
  geom_violin(alpha = 0.5, fill="grey") 
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiOnRn-ICC4wr9YLnw-%2F-LiOp4PTlf8ipeT7JUbn%2Fimg3.png?alt=media\&token=c054618e-1d27-4926-9bfd-968fbb446aea)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
  geom_jitter(width=0.1, height=0)+
  geom_violin(alpha = 0.5, fill="grey")+
  geom_boxplot(width = 0.6, alpha=0.5)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiOnRn-ICC4wr9YLnw-%2F-LiOp8YV8tnfLQbYpXNb%2Fimg4.png?alt=media\&token=2d530251-3e2c-424a-a435-fc037a9f02f3)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
  geom_jitter(width=0.1, alpha=0.5)+
  geom_violin(alpha = 0.5, fill="grey", position = position_nudge(x=0.6))+
  geom_boxplot(width = 0.3, alpha=0.5)+
  coord_flip()+
  theme_classic()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiOnRn-ICC4wr9YLnw-%2F-LiOpEFU9RwE5ZsY1DVs%2Fimg1.png?alt=media\&token=fc5214be-ee79-42fc-8113-a9c3ba587b27)
{% endtab %}

{% tab title="Code" %}

```
ggplot()+
  geom_histogram(aes(x=Sepal.Length), fill="green", alpha = 0.5, data=iris)+
  geom_histogram(aes(x=Petal.Length), fill="red", alpha=0.5, data=iris)+
  facet_wrap(~Species)+
  theme_dark()+
  labs(x="Length of sepals (green), length of petals (red)", y="Number of flowers with these features")
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiP0wLmecW1MROKofGd%2F-LiP16I2Lds50A-hlar9%2Fimg6.png?alt=media\&token=a3a331be-150f-4235-b17d-95105096e92e)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(x=Sepal.Width))+
  geom_histogram(aes(fill=Species), color="black")+
  xlab("Sepal width")+
  ylab("Count")+
  ggtitle("Histogram of sepal width")
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Image" %}
![](https://3364608434-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LD2B3y86yJyNeihFLqD%2F-LiP0wLmecW1MROKofGd%2F-LiP2YbWeAxJW93jDU7k%2Fimage7.png?alt=media\&token=f5cdd775-7421-445d-8844-37c705bc3c6c)
{% endtab %}

{% tab title="Code" %}

```
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width))+
  geom_point(aes(color=Petal.Width, shape=Species), size=2)+
  scale_color_gradient(low = "yellow", high = "red")+
  theme_grey()
```

{% endtab %}
{% endtabs %}
