ggplot()+geom_bar(DATA,aes(X,Y)) (Normal) hchart(DATA,'column',hcaes(X,Y)) (Interactif) library(ggplot)
ggplot(data= YOUR_DATASET, aes(x= "", y= Y_AXIS_VAR, fill= GROUP_VAR)+
geom_bar(stat="identity",
color="white") + # Optional
coord_polar("y", start = 0) +
ggtitle("YOUR TITLE") + # The Graph title
theme_void() + # Optional
theme(plot.title = element_text(size = 15, hjust = 0.5), # Optional
panel.grid.minor = element_blank(), # Optional
panel.grid.major.x = element_blank() # Optional
) ab_nyc2019.csv ?skim) library(tidyverse)
library(skimr)
location <- read_csv('/data/session6/ab_nyc2019.csv')
location %>%
skim
count_loc <- sub_loc %>%
group_by(neighbourhood_group) %>%
summarise(n_appart=n()) %>%
ungroup() %>%
arrange(desc(neighbourhood_group)) %>%
mutate(pct = round(100*n_appart/sum(n_appart),1),
pct_label = cumsum(pct) - 0.5*pct,
n_label = ifelse(n_appart>4000, format(n_appart, digits=9, big.mark=" ", small.interval=3),""),
nb_pct = paste0(neighbourhood_group, " (",pct,"%)"))
pie1 <- ggplot(count_loc, aes(x="", y=pct, fill=nb_pct)) +
geom_bar(stat = "identity", color = "white") +
coord_polar("y", start = 0) +
labs(fill="Quartiers",
title = "Répartition du nombre de location/ndisponible par quartier en 2019") +
geom_text(aes( y = pct_label, label = n_label), color = "white") +
theme_void() +
theme(plot.title = element_text(size = 10, face = "bold", hjust = 4),
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank()) sub_loc <- sub_loc %>%
mutate(neighbourhood_group=ifelse(neighbourhood_group %in% c("St. George", "Staten Island",
"Bronx"), "Autres*", neighbourhood_group))
count_loc <- sub_loc %>%
group_by(neighbourhood_group) %>%
summarise(n_appart=n()) %>%
ungroup() %>%
arrange(desc(neighbourhood_group)) %>%
mutate(pct = round(100*n_appart/sum(n_appart),0),
pct_label = cumsum(pct) - 0.5*pct,
n_label = ifelse(n_appart>4000, format(n_appart, digits=9,
big.mark=" ", small.interval=3),""),
nb_pct = paste0(neighbourhood_group, " (",pct,"%)"))
hchart(count_loc, "pie", hcaes(x=neighbourhood_group, y = n_appart)) %>%
hc_tooltip(pointFormat = "nbre de biens: <b>{point.y}</b>") %>%
hc_title( text="Répartition du nombre de location<br>
disponible par quartier en 2019") %>%
hc_credits(
enabled = TRUE, text = "Source: Kaggle",
href = "https://www.kaggle.com/dgomonov/new-york-city-airbnb-open-data",
style = list(fontSize = "12px")) %>%
hc_caption(
text = "*Comprend les quartiers du Bronx, St. George et Staten Island ",
align = "right") %>%
hc_plotOptions(pie =list(dataLabels = list(enabled = TRUE,
format="{point.neighbourhood_group}: {point.percentage:.2f} %"))) ggplot()+geom_bar(DATA,aes(X,Y))+coord_polar("y", start = 0) (Normal) hchart(DATA,'pie',hcaes(X,Y)) (Interactif) Merci pour votre attention