library(tidyverse) # 1. ggplot(starwars, aes(x = height, y = mass, color = sex, shape = gender)) + geom_point() starwars %>% slice_max(mass) starwars %>% slice_max(mass) %>% select(name) ggplot(starwars %>% filter(name!="Jabba Desilijic Tiure"), aes(x = height, y = mass, color = sex, shape = gender)) + geom_point() # 2. ggplot(starwars %>% filter(name!="Jabba Desilijic Tiure"), aes(x = height, y = mass, color = sex, shape = gender)) + geom_point(col = "pink3") # 3. ggplot(starwars %>% filter(name!="Jabba Desilijic Tiure"), aes(x = height, y = mass, shape = gender)) + geom_point(color = "pink3") + labs( title = "Mass vs. Height | Gender", x = "Height", y = "Mass", shape = "Gender" ) # 4. ggplot(starwars, aes(x = height)) + geom_histogram(color = "darkslategray", fill = "peachpuff") + labs(title = "Distribuzione dell'altezza dei personaggi di Star Wars", x = "Height", y = "Frequenza") ggplot(starwars, aes(x = height)) + geom_histogram(binwidth = 18, color = "darkslategray", fill = "peachpuff") + labs(title = "Distribuzione dell'altezza dei personaggi di Star Wars", x = "Height", y = "Frequenza") starwars %>% pull(height) # 5. ggplot(starwars, aes(x = height, y = sex)) + geom_boxplot() + labs(title = "Distribution of height conditional to biological sex of the character", x = "Height", y = "Sex") ggplot(starwars, aes(x = height, y = species)) + geom_dotplot(binwidth=1) + labs(title = "Distribuzione dell'altezza dei personaggi condizionatamente alla specie", x = "Height", y = "Species") # 6. ggplot(starwars, aes(y = eye_color)) + geom_bar(width=0.5, fill = "white", col="black") ggplot(starwars, aes(y = eye_color)) + geom_bar(width=0.5, fill = "white", col="black") + theme(aspect.ratio = .4) # 7. ggplot(starwars, aes(y = eye_color, fill = hair_color)) + geom_bar(position = "fill") + labs(title = "Hair color | Eye color", y = "Eye color", x = "Proportion", fill = "Hair color") ggplot(starwars, aes(y = eye_color, fill = hair_color)) + geom_bar(position = "dodge") + labs(title = "Hair color | Eye color", y = "Eye color", x = "Count", fill = "Hair color") # 8. ggplot(starwars, aes(x = height, y = mass, color = sex, shape = gender, size = birth_year)) + geom_point(alpha = .75) + labs(title = "Mass vs. Height of Star Wars characters", x = "Height", y = "Mass", color = "Sex", shape = "Gender", size = "Birth year (BBY)") ggplot(starwars, aes(x = height, y = mass, color = sex, size = birth_year)) + geom_point() + facet_grid(sex ~ gender) + labs(title = "Mass vs. Height of Star Wars characters", x = "Height", y = "Mass", color = "Sex", size = "Birth year (BBY)") ggplot(data = drop_na(starwars[, c("height", "mass", "birth_year", "sex" ,"gender")]), aes(x = height, y = mass, color = sex, size = birth_year)) + geom_point() + facet_grid(gender ~ sex) + labs(title = "Mass vs. Height of Star Wars characters", x = "Height", y = "Mass", color = "Sex", size = "Birth year (BBY)") + theme(legend.position = "bottom")