# ggplot2 examples
library(ggplot2)
# create factors with value labels
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
labels=c("3gears","4gears","5gears"))
mtcars$am <- factor(mtcars$am,levels=c(0,1),
labels=c("Automatic","Manual"))
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),
labels=c("4cyl","6cyl","8cyl"))
# Kernel density plots for mpg
# grouped by number of gears (indicated by color)
g = qplot(mpg, data=mtcars, geom="density", fill=gear, alpha=I(.5),
main="Distribution of Gas Mileage", xlab="Miles Per Gallon",
ylab="Density")
g
install.packages("remotes")
remotes::install_github("olihawkins/clplot")
library(ggplot2)
library(clplot)
g + theme_commonslib()
#install.packages("leaflet")
library(leaflet)
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
library(htmlwidgets)
library(IRdisplay)
saveWidget(m, 'demo.html', selfcontained = TRUE)
display_html('')
install.packages("kableExtra")
library(knitr)
library(kableExtra)
kable(summary(cars)) %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
as.character() %>% display_html()
library(tidyverse)
library(httr)
library(jsonlite)
path <- "https://data.police.uk/api/crimes-street/burglary?"
request <- GET(url = path,
query = list(
lat = 52.0406,
lng = -0.7594,
date = "2018-05")
)
response <- content(request, as = "text", encoding = "UTF-8")
df <- fromJSON(response, flatten = TRUE) %>%
data.frame()
head(df)
#install.packages("hablar")
library(hablar)
df <- select(df,
month, category,
location = location.street.name,
long = location.longitude,
lat = location.latitude) %>%
convert(num(long, lat))
head(df)
m = leaflet(df) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions(), popup = ~as.character(location)
)
saveWidget(m, 'demo.html', selfcontained = TRUE)
display_html('')