library(tidyverse) # il dataset di esempio รจ nel pacchetto MASS require(MASS) # barre verticali farms %>% ggplot(aes(x = Manag)) + geom_bar() # colore arancione farms %>% ggplot(aes(x = Manag)) + geom_bar(fill = "orange") # colore definito dalla variabile (mapping) farms %>% ggplot(aes(x = Manag)) + geom_bar(aes(fill = Manag)) # a barre sovrapposte farms %>% ggplot(aes(x = factor(1))) + # fattore = 1 geom_bar(width = 0.4, # larghezza della barra aes(fill = Manag)) + theme_minimal() # barre orizzontali farms %>% ggplot(aes(x = Manag)) + geom_bar(fill = "blue") + coord_flip() + ylab("Frequenze") # differenza da un punto Orange %>% # creo una variabile "scarti": mutate("scarti" = circumference - mean(circumference)) %>% ggplot(aes(x = Tree, y = scarti)) + geom_col(width = 0.7, aes(fill = scarti)) + ylab("circumference (scarti)") + theme_minimal() + coord_flip() # DUE VARIABILI # barre sovrapposte farms %>% ggplot(aes(x = Manag)) + geom_bar(aes(fill = Use)) # barre raggruppate farms %>% ggplot(aes(Manag)) + geom_bar(aes(fill = Use), position="dodge") ## TABELLE E DATI RIASSUNTIVI # tabella di esempio tab1 <- as.data.frame(table(farms$Manag)) colnames(tab1) <- c("Manag", "Freq") # geom_col tab1 %>% ggplot(aes(Manag, Freq)) + geom_col() ## BARRE ORDINATE IN BASE A FREQUENZE farms %>% group_by(Manag) %>% count() %>% # ordine decrescente ggplot(aes(x = reorder(Manag, -n), y = n, fill = Manag)) + geom_col()