library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.6 v purrr 0.3.4
## v tibble 3.1.7 v dplyr 1.0.9
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.1.3
## Warning: package 'tibble' was built under R version 4.1.3
## Warning: package 'tidyr' was built under R version 4.1.3
## Warning: package 'readr' was built under R version 4.1.3
## Warning: package 'purrr' was built under R version 4.1.3
## Warning: package 'dplyr' was built under R version 4.1.3
## Warning: package 'stringr' was built under R version 4.1.3
## Warning: package 'forcats' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
data("starwars")
head(starwars)
## # A tibble: 6 x 14
## name height mass hair_color skin_color eye_color birth_year sex gender
## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 Luke Sky~ 172 77 blond fair blue 19 male mascu~
## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu~
## 3 R2-D2 96 32 <NA> white, bl~ red 33 none mascu~
## 4 Darth Va~ 202 136 none white yellow 41.9 male mascu~
## 5 Leia Org~ 150 49 brown light brown 19 fema~ femin~
## 6 Owen Lars 178 120 brown, gr~ light blue 52 male mascu~
## # ... with 5 more variables: homeworld <chr>, species <chr>, films <list>,
## # vehicles <list>, starships <list>
View(starwars)
library(ggplot2)
starwars$sex <- as.factor(starwars$sex)
starwars$species <- as.factor(starwars$species)
starwars$eye_color <- as.factor(starwars$eye_color)
ggplot(starwars, aes(x = sex, fill = species)) +
theme_bw()+
geom_bar()+
labs( x=" Gender of the starwars characters",
title = "Gender filled with Species")

prop.table(table(starwars$species))
##
## Aleena Besalisk Cerean Chagrian Clawdite
## 0.01204819 0.01204819 0.01204819 0.01204819 0.01204819
## Droid Dug Ewok Geonosian Gungan
## 0.07228916 0.01204819 0.01204819 0.01204819 0.03614458
## Human Hutt Iktotchi Kaleesh Kaminoan
## 0.42168675 0.01204819 0.01204819 0.01204819 0.02409639
## Kel Dor Mirialan Mon Calamari Muun Nautolan
## 0.01204819 0.02409639 0.01204819 0.01204819 0.01204819
## Neimodian Pau'an Quermian Rodian Skakoan
## 0.01204819 0.01204819 0.01204819 0.01204819 0.01204819
## Sullustan Tholothian Togruta Toong Toydarian
## 0.01204819 0.01204819 0.01204819 0.01204819 0.01204819
## Trandoshan Twi'lek Vulptereen Wookiee Xexto
## 0.01204819 0.02409639 0.01204819 0.02409639 0.01204819
## Yoda's species Zabrak
## 0.01204819 0.02409639
ggplot(starwars, aes(x = height, y = mass))+
geom_point(color='red')+
labs(
x = "height of the starwars character",
y = "mass of starwars character",
title = "Starwars"
)
## Warning: Removed 28 rows containing missing values (geom_point).

ggplot(starwars, aes(x = height)) +
theme_bw()+
geom_histogram( binwidth = 5)
## Warning: Removed 6 rows containing non-finite values (stat_bin).

ggplot(starwars, aes(x = height)) +
theme_bw()+
geom_density()
## Warning: Removed 6 rows containing non-finite values (stat_density).

star <- starwars %>% subset(species == "Human" | species == "Droid" | species == "Gungan")
ggplot(star, aes(species, mass))+
geom_boxplot()
## Warning: Removed 16 rows containing non-finite values (stat_boxplot).

a <- ggplot(starwars, aes(mass))
a <- a + geom_density(binwidth = 10)
## Warning: Ignoring unknown parameters: binwidth
a
## Warning: Removed 28 rows containing non-finite values (stat_density).

a <- a + theme_light()
a <- a + theme(axis.title = element_text(size = 13, face = "bold"),
axis.text = element_text(size = 11))
a
## Warning: Removed 28 rows containing non-finite values (stat_density).

ggplot(starwars, aes(x = mass)) +
theme_bw()+
geom_histogram( binwidth = 10)
## Warning: Removed 28 rows containing non-finite values (stat_bin).

ggplot(starwars, aes(x = mass)) +
theme_bw()+
geom_density()
## Warning: Removed 28 rows containing non-finite values (stat_density).
