back to notes

barplot in ggplot

'
starwars %>%
group_by(species) %>%
arrange(species) %>%
ggplot(aes(species, ..count..)) +
geom_bar() +
coord_flip()
'

'
starwars %>%
head(20) %>%
ggplot(aes(species, ..count..)) +
geom_bar()
'

'
org_links %>%
select(-attributes) %>%
mutate(status = map_chr(str_split(vivoType, "#"), 2)) %>%
group_by(status) %>%
count() %>%
ggplot(aes(x = reorder(status, -n), y = n)) +
geom_bar(stat = "identity")
'

'
fct_count(starwars$eye_color, sort = TRUE) %>%
ggplot(aes(x = fct_reorder(f, n), y = n)) +
geom_bar(stat = "identity") +
theme(axis.text.y = element_text(angle = 45, hjust = 1)) +
labs(x = "Eye Color", y = "Number of occurrences") +
coord_flip()
'


last updated april 2018