Created
July 18, 2016 17:51
-
-
Save slopp/df604a5798f45f75178e97c9cf6857f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: 'Notebook: htmwlwidgets' | |
output: | |
html_notebook: default | |
html_document: default | |
--- | |
## dygraphs | |
https://github.com/rstudio/dygraphs | |
Dygraphs provides rich facilities for charting time-series data in R and includes support for many interactive features including series/point highlighting, zooming, and panning. | |
```{r} | |
library(dygraphs) | |
dygraph(nhtemp, main = "New Haven Temperatures") %>% | |
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01")) | |
``` | |
## Leaflet | |
http://rstudio.github.io/leaflet/ | |
Leaflet is a JavaScript library for creating dynamic maps that support panning and zooming along with various annotations like markers, polygons, and popups. | |
```{r, message=FALSE, warning=FALSE} | |
library(leaflet) | |
cities <- read.csv("cities.csv") | |
leaflet(cities) %>% addTiles() %>% | |
addCircles(lng = ~Long, lat = ~Lat, weight = 1, | |
radius = ~sqrt(Pop) * 30, popup = ~City | |
) | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Python and R with Feather" | |
output: html_notebook | |
--- | |
```{r setup, include=FALSE} | |
library(feather) | |
library(ggplot2) | |
setwd('~/sol-eng-sales/vignettes/notebooks/demos/5-feather') | |
``` | |
First use bash to append together several data files into a single file we can read and manipulate: | |
```{bash} | |
cat flights1.csv flights2.csv flights3.csv > flights.csv | |
``` | |
Now use **pandas** to read and filter the data. We'll pass it to R using the high-performance [feather](https://blog.rstudio.org/2016/03/29/feather/) serialization format: | |
```{python} | |
import pandas | |
import feather | |
# Read flights data and select flights to O'Hare | |
flights = pandas.read_csv("flights.csv") | |
flights = flights[flights['dest'] == "ORD"] | |
# Select carrier and delay columns and drop rows with missing values | |
flights = flights[['carrier', 'dep_delay', 'arr_delay']] | |
flights = flights.dropna() | |
print flights.head(10) | |
# Write to feather file for reading from R | |
feather.write_dataframe(flights, "flights.feather") | |
``` | |
Now read from *flights.feather* into an R data frame and plot arrival delays by carrier using **ggplot2**: | |
```{r} | |
library(feather) | |
library(ggplot2) | |
# Read from feather and plot | |
flights <- read_feather("flights.feather") | |
ggplot(flights, aes(carrier, arr_delay)) + geom_boxplot() | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment