Skip to content

Instantly share code, notes, and snippets.

View andrewbtran's full-sized avatar

Andrew Tran andrewbtran

View GitHub Profile
@andrewbtran
andrewbtran / Circles on Leaflet R map
Last active August 29, 2015 14:23
Add multiple circles to Leaflet R map
ct <- read.csv("ctlist.csv", stringsAsFactors=FALSE) # Brings in the file 'ctlist.csv'
# Be sure to first set the working directory in R to where the file is listed
m <- leaflet(ct) %>% addTiles('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
attribution='Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>')
m %>% setView(-72.690940, 41.651426, zoom = 8)
m %>% addCircles(~lng, ~lat, popup=ct$type, weight = 3, radius=40,
color="#ffa500", stroke = TRUE, fillOpacity = 0.8)
@andrewbtran
andrewbtran / Leaflet JS circles
Last active June 20, 2024 13:39
Add multiple circles to Leaflet JS
<html>
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<style>
#map { height: 400px; }
</style>
</head>
<body>
<div id="map"></div>
@andrewbtran
andrewbtran / Add marker Leaflet R
Created June 22, 2015 04:12
Leaflet R marker
m <- leaflet() %>%
addTiles() %>%
setView(-72.690940, 41.651426, zoom = 8) %>%
addMarkers(lng=-72.690940, lat=41.651426, popup="<b>Hello</b><br><a href='http://www.trendct.org'>-TrendCT.org</a>")
m
@andrewbtran
andrewbtran / Leaflet JS marker
Created June 22, 2015 04:08
Add marker Leaflet JS
<html>
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<style>
#map { height: 200px; }
</style>
</head>
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
setView(-72.690940, 41.651426, zoom = 8)
m # Print the map
@andrewbtran
andrewbtran / Leaflet JS staging
Created June 22, 2015 03:43
Stage map area in Leaflet
<html>
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<style>
#map { height: 200px; }
</style>
</head>
@andrewbtran
andrewbtran / LeafletJS R intro
Last active August 29, 2015 14:23
Leaflet: Loading R library
install.packages("leaflet")
library(leaflet)
install.packages("dplyr")
library(dplyr)
@andrewbtran
andrewbtran / LeafletJS intro
Created June 22, 2015 03:17
Leaflet: Loading in Javascript and CSS libraries into the HTML
<html>
<head>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
</head>
<body>
</body>
</html>
@andrewbtran
andrewbtran / saveascsv
Created June 12, 2015 01:55
save file r
head(merged)
#Save it as a csv
write.csv(merged, "merged.csv")
@andrewbtran
andrewbtran / advanced pivot table r
Created June 12, 2015 01:53
Advanced pivot table r
#Advanced calculations
income <- tapply(earnings$TOTAL.EARNINGS, earnings$DEPARTMENT.NAME, sum)
#Convert the table into a dataframe
income <- data.frame(income)
#Create a column based on row names
income$Department <- rownames(income)
#Need the column of rown names to merge it with the department workers count