ggplot - διαγράμματα κανονικής κατανομής

Το βίντεο έχει διάρκεια 28:27. Πιθανά να χρειάζεται λίγος χρόνος για την προβολή του.


rstats distributions ggplot
library(tidyverse)
library(scales)
library(cowplot)

# base
ggplot() +
  geom_function(fun = dnorm,
                color = "navyblue",
                size = 1) +
  scale_x_continuous(limits = c(-4, 4)) +
  labs(x = "Z", y = "Πυκνότητα") +
  theme_cowplot() 

# args list
ggplot() +
  geom_function(fun = dnorm, 
                color = "navyblue", 
                size = 1,
                args = list(mean = 0, sd = 2)) +
  scale_x_continuous(limits = c(-8, 8), 
                     breaks = pretty_breaks(10)) +
  labs(x = "Z", y = "Πυκνότητα") +
  theme_cowplot()


# fully parametrized
M <- 100
S <- 20
ggplot() +
  geom_function(fun = dnorm, 
                color = "navyblue", 
                size = 1,
                args = list(mean = M, sd = S)) +
  scale_x_continuous(limits = c(M-4*S, M+4*S), 
                     breaks = pretty_breaks(10)) +
  labs(x = "", y = "Πυκνότητα") +
  theme_cowplot()

M <- 0
S <- 1
x <- seq(from = M-4*S, to = M+4*S, length.out = 1001)
y <- dnorm(x, mean = M, sd = S)
df <- tibble(x, y) 

df %>% 
  ggplot(aes(x = x, y = y)) +
  geom_area(data = filter(df, x < -2), 
            fill = "skyblue",
            alpha = 0.5) +
  geom_line(color = "navyblue", size = 1) +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  labs(x = "", y = "Πυνκότητα") +
  theme_cowplot() 


df %>% 
  ggplot(aes(x = x, y = y)) +
  geom_area(data = filter(df, x > -1 & x < 1), 
            fill = "skyblue",
            alpha = 0.9) +
  geom_area(data = filter(df, x > -2 & x < 2), 
            fill = "skyblue",
            alpha = 0.6) +
  geom_area(data = filter(df, x > -3 & x < 3), 
            fill = "skyblue",
            alpha = 0.3) +
  geom_line(color = "navyblue", size = 1) +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  labs(x = "", y = "Πυνκότητα") +
  theme_cowplot() 

M <- 0
S <- 1
x <- seq(from = M-4*S, to = M+4*S, length.out = 1001)
y <- dnorm(x, mean = M, sd = S)
cy <- cumsum(y) * (8*S/1000)
df <- tibble(x, y, cy)

df %>% 
  ggplot(aes(x = x, y = cy)) +
  geom_line(color = "navyblue", size = 1) +
  scale_x_continuous(breaks = pretty_breaks(10)) +
  scale_y_continuous(breaks = pretty_breaks(10)) +
  labs(x = "", y = "Αθροιστική Πυνκότητα") +
  theme_minimal_grid()  

Συνδεθείτε για περισσότερες δυνατότητες αλληλεπίδρασης,
σχολιασμοί, εξωτερικοί σύνδεσμοι, βοήθεια, ψηφοφορίες, αρχεία, κτλ.

Creative Commons License
Εκπαιδευτικό υλικό από τον Αθανάσιο Σταυρακούδη σας παρέχετε κάτω από την άδεια Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.
Σας παρακαλώ να ενημερωθείτε για κάποιους επιπλέον περιορισμούς
http://stavrakoudis.econ.uoi.gr/stavrakoudis/?iid=401.