Syntaxe facile :
ggplot(data) +geom_line(aes(x,y,color)) +ggtitle('Titre') +xlab('titre x')+ylab('titre y')+ au lieu de %>% library(ggplot2)
ggplot(data= YOUR_DATASET)+
geom_line(aes(x= X_AXIS_VAR, y= Y_AXIS_VAR, color= COLOR_VAR)) +
ggtitle("YOUR TITLE")+ # The Graph title
xlab("YOUR X LABEL") + # If you want something different
ylab("YOUR Y LABEL") + # from X_AXIS_VAR & Y_AXIS_VAR
theme_minimal() + # 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
)population_lux.xls year et taille de la population dans la variable population library(tidyverse)
library(readxl)
library(janitor)
pop <- read_xlsx('/data/population_lux.xlsx')
pop_long <- pop %>%
filter(Population=='Population totale (x 1 000)') %>%
pivot_longer(-Population, names_to = 'date', values_to = 'nombre') %>%
mutate(date=as.numeric(date),
nombre = str_replace_all(nombre,',','.'),
nombre = str_trim(nombre),
nombre = as.numeric(nombre))
p1 <- ggplot(data=pop_long) +
geom_line(aes(x=date, y=nombre), color='#88a3df') +
ggtitle("Evolution du nombre d'habitant\n au Luxembourg entre 1981 et 2021") +
xlab("Année") +
ylab("Effectif (x100)")
p1 +
theme_minimal() +
theme(plot.title = element_text(size = 14, colour = "#717171", face = "bold", hjust = 0.5),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
axis.title.x = element_text(colour = "#717171"),
axis.title.y = element_text(colour = "#717171"),
legend.position="none",
text=element_text(family="Roboto"))facet_wrap()ggplot(data=stocks_long2)+
geom_line(aes(x=date, y=indice, color=new_stocks)) +
labs(color ="Stocks") +
theme_minimal() +
facet_wrap(~Population, nrow = 3)facet_wrap()library(ggplot2)
ggplot(data= YOUR_DATASET)+
#geom_line(aes(x= X_AXIS_VAR, y= Y_AXIS_VAR, color= COLOR_VAR)) +
geom_point(aes(x= X_AXIS_VAR, y= Y_AXIS_VAR, color= COLOR_VAR)) +
ggtitle("YOUR TITLE")+ # The Graph title
xlab("YOUR X LABEL") + # If you want something different
ylab("YOUR Y LABEL") + # from X_AXIS_VAR & Y_AXIS_VAR
theme_minimal() + # 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
)athome.csv luxflat <- read_rds('/data/luxflat.rds')
sub_luxflat <- luxflat %>%
filter(quartier %in% c('Beggen', 'Belair', 'Gasperich','Kirchberg') & meuble==0)
ggplot(data=sub_luxflat) +
geom_point(aes(x=surface, y=prix, color=quartier)) +
ggtitle("Loyer d'appartements en Ville par\n rapport à la surface au 1er Juin 2020") +
labs(fill = "Quartiers") +
xlab("Surface (m²)") +
ylab("Loyer (€)") +
theme_minimal() +
theme(plot.title = element_text(size = 15, face = "bold", hjust = 0.5),
panel.grid.minor = element_blank(),
legend.justification=c(1,0),
legend.position=c(0.95,0.02)) ?slice) facet_wrap() meublemeuble_quartier <- luxflat %>%
filter(meuble==1) %>%
group_by(quartier) %>%
summarise(n_appart=n()) %>%
ungroup() %>%
arrange(desc(n_appart)) %>%
slice(1:3)
luxflat %>%
filter(meuble==1) %>%
group_by(quartier) %>%
summarise(n_appart=n()) %>%
ungroup() %>%
arrange(n_appart) %>%
slice(1:3)
luxflat %>%
group_by(quartier) %>%
summarise(prix_max = max(prix),
prix_min = min(prix),
prix_med = median(prix),
surf_max = max(surface),
surf_min = min(surface),
surf_med = median(surface) )ggplot(data=luxflat %>%
filter(quartier %in% meuble_quartier$quartier) %>%
mutate(meuble= ifelse(meuble==1,
'Appartements meublés','Appartements non meublés'))) +
geom_point(aes(x=surface, y=prix, color=quartier), alpha=0.8, position = 'jitter') +
facet_wrap(~meuble, nrow = 2) +
ggtitle("Loyer d'appartements en Ville par\n rapport à la surface au 1er Juin 2020") +
xlab("Surface (m²)") +
ylab("Loyer* (€)") +
theme_light()+
theme(plot.title = element_text(size = 15,
face = "bold", hjust = 0.5),
plot.caption = element_text(size = 8,
face = "bold",color='#cecece'),
#panel.grid.minor = element_blank(),
legend.position= 'bottom')+
labs(color = " ",
caption = "Source: atHome \n*Le loyer comprend les charges mensuelles")library(ggplot)
ggplot(data= YOUR_DATASET)+
geom_bar(aes(x= X_AXIS_VAR, y= Y_AXIS_VAR, fill= COLOR_VAR), stat="identity") +
# geom_bar(aes(x= X_AXIS_VAR)) +
ggtitle("YOUR TITLE")+ # The Graph title
xlab("YOUR X LABEL") + # If you want something different
ylab("YOUR Y LABEL") + # from X_AXIS_VAR & Y_AXIS_VAR
theme_minimal() + # Optional
theme(plot.title = element_text(size = 15, hjust = 0.5), # Optional
panel.grid.minor = element_blank(), # Optional
panel.grid.major.x = element_blank())Chaque ligne correspond à un diamant
ggplot(data= diamonds)+
geom_bar(aes(x= cut)) +
ggtitle("Nombre de diamants par niveau de qualité")+ # Titre
xlab("Qualité des diamants") + # Titre axe horizontal
ylab("Volume") + # Titre axe vertical
theme_minimal() + # Optional
theme(plot.title = element_text(size = 15, hjust = 0.5), # Optional
panel.grid.minor = element_blank(), # Optional
panel.grid.major.x = element_blank())ggplot(data= pop)+
geom_bar(aes(x= county, y= popdensity), stat="identity") +
ggtitle("Comparaison de la densité de population pour 5 comtés de l'Illinois")+ # The Graph title
xlab("Comté") + # If you want something different
ylab("densité") + # from X_AXIS_VAR & Y_AXIS_VAR
theme_minimal() + # Optional
theme(plot.title = element_text(size = 15, hjust = 0.5), # Optional
panel.grid.minor = element_blank(), # Optional
panel.grid.major.x = element_blank())Ordonner les barres
ggplot(data= pop %>%
mutate(county= factor(county, levels=c('BOONE','ADAMS','ALEXANDER','BOND','BROWN'))))+
geom_bar(aes(x= county, y= popdensity), stat="identity") +
ggtitle("Comparaison de la densité de population pour 5 comtés de l'Illinois")+ # The Graph title
xlab("Comté") + # If you want something different
ylab("densité") + # from X_AXIS_VAR & Y_AXIS_VAR
theme_minimal() + # Optional
theme(plot.title = element_text(size = 15, hjust = 0.5), # Optional
panel.grid.minor = element_blank(), # Optional
panel.grid.major.x = element_blank())Ordonner les barres
forcatsAvec forcats, il est possible d’inverser les “levels”
Ordonner les barres
quantile(,0.50)) via un diagramme en barre.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
) athome.csv ggplot()+geom_line(DATA, aes(X,Y)) ggplot()+geom_bar(DATA,aes(Y,Y), stat="identity") ggplot()+geom_bar(DATA,aes(X,Y))+coord_polar("y", start = 0) Merci pour votre attention