This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist ## Min. : 4.0 Min. : 2.00 ## 1st Qu.:12.0 1st Qu.: 26.00 ## Median :15.0 Median : 36.00 ## Mean :15.4 Mean : 42.98 ## 3rd Qu.:19.0 3rd Qu.: 56.00 ## Max. :25.0 Max. :120.00
library(tidyverse)
library(ggplot2) library(ggflags) library(countrycode) dat <- tibble(country = toupper(c("US", "Italy", "Canada", "UK", "Japan", "Germany", "France", "Russia")), count = c(3.2, 0.71, 0.5, 0.1, 0, 0.2, 0.1, 0), label = c(as.character(c(3.2, 0.71, 0.5, 0.1, 0, 0.2, 0.1)), "No Data"), code = c("br", "it", "ca", "gb", "jp", "de", "fr", "ru")) dat %>% mutate(country = reorder(country, -count)) %>% ggplot(aes(country, count, label = label)) + geom_bar(stat = "identity", fill = "darkred") + geom_text(nudge_y = 0.2, color = "darkred", size = 5) + geom_flag(y = -.5, aes(country = code), size = 12) + scale_y_continuous(breaks = c(0, 1, 2, 3, 4), limits = c(0,4)) + geom_text(aes(6.25, 3.8, label = "Source UNODC Homicide Statistics")) + ggtitle(toupper("Homicide Per 100,000 in G-8 Countries")) + xlab("") + ylab("# of gun-related homicides\nper 100,000 people") + ggthemes::theme_economist() + theme(axis.text.x = element_text(size = 8, vjust = -16), axis.ticks.x = element_blank(), axis.line.x = element_blank(), plot.margin = unit(c(1,1,1,1), "cm"))
You can also embed plots, for example:
plot(cars)