diamonds %>% slice(1:100) %>%
ggplot(aes(x=depth,
y=carat)) +
geom_point( color="purple", size= 1, shape=5, alpha=0.9)
diamonds %>% slice(1:30) %>%
ggplot(aes(x=carat,
y=price, color=cut)) +
geom_point(size= 5, shape=18, alpha=0.7)
diamonds %>% slice(1:30) %>%
ggplot(aes(x=carat,
y=price,
color=cut,
size=cut)) +
geom_point(shape=4, alpha=1)
diamonds %>% slice(1:30) %>%
ggplot(aes(x=carat,
y=price)) +
geom_point(size=1, shape=21) +
geom_smooth(method = "lm", se=TRUE, color="pink")
## `geom_smooth()` using formula = 'y ~ x'
diamonds %>% filter(cut=="Fair") %>%
ggplot(mapping=aes(x=carat,
y=depth, color=clarity)) +
geom_line(linewidth=1, lty=3)
Farklı claritydeki elmasların carat ve price çizgi grafiğini oluşturmak için son satırda yer alan facet_wrap fonksiyonu kullandım. Hangi değikene göre farklı grafikler istiyorsam vars fonksiyonu içerisinde yazdım.
diamonds %>% slice(1:100) %>%
ggplot(aes(x=carat,
y=price)) +
geom_line(linewidth=2) +
facet_wrap(vars(clarity))
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
Grafik eksenlerini isimlendirmek için labs fonksiyonunu kullandım.
diamonds %>% slice(1:100) %>%
ggplot(aes(x=depth)) +
geom_density(color="red", fill="pink", adjust=0.6, alpha=0.5, linetype="dashed", linewidth=1) +
labs(x="DEPTH", y="DENSITY")
Farklı kesim türlerine göre fiyat karşılaştırması yapmak isteseydik öncelikle filter ile farklı kesim türlerine göre verisetimi düzenlerdim. Sonnrasında, üç ayrı geom_density fonksiyonunu kullanarak aynı düzlemde üç histogramı üst üste gösterebiliriz.
diamond_1 <- diamonds %>% filter(cut=="Ideal")
diamond_2 <- diamonds %>% filter(cut=="Very Good")
diamond_3 <- diamonds %>% filter(cut=="Good")
ggplot() +
geom_density(data=diamond_1, aes(x=price),
color="green", fill="lightgreen",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1) +
geom_density(data=diamond_2, aes(x=price),
color="red", fill="pink",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1) +
geom_density(data=diamond_3, aes(x=price),
color="blue", fill="lightblue",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1)
Grafik üzerinde belirli değerleri çizg ile göstermek istediğim için geom_vline fonksiyonunu kullandım.
diamond_1 <- diamonds %>% filter(cut=="Ideal")
diamond_2 <- diamonds %>% filter(cut=="Very Good")
diamond_3 <- diamonds %>% filter(cut=="Good")
ggplot() +
geom_density(data=diamond_1, aes(x=price),
color="green", fill="lightgreen",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1) +
geom_density(data=diamond_2, aes(x=price),
color="red", fill="pink",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1) +
geom_density(data=diamond_3, aes(x=price),
color="blue", fill="lightblue",
adjust=0.8, alpha=0.5,
linetype="dashed", linewidth=1) +
geom_vline(xintercept = 5000, linetype="dashed", linewidth=0.3) +
geom_vline(xintercept = 10000, linetype="dashed", linewidth=0.3) +
geom_vline(xintercept = 15000, linetype="dashed", linewidth=0.3)
Umarım bunların hepsini sınavda da yapabilirim.
library(emo)
print(emo::ji("smile"))
## 😄