Skip to content
This repository was archived by the owner on Sep 30, 2021. It is now read-only.

Commit 1aee67d

Browse files
author
Bhaskar Karambelkar
committed
Trying out packrat
1 parent 53a0aa8 commit 1aee67d

15 files changed

+688
-227
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
docs
88
^.*\.png$
99
^.*\.gif$
10+
^packrat/
11+
^\.Rprofile$

.Rprofile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### -- Packrat Autoloader (version 0.4.8-1) -- ####
2+
source("packrat/init.R")
3+
#### -- End Packrat Autoloader -- ####

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.Ruserdata
55
*.swp
66
.DS_Store
7+
packrat/lib*/
8+
packrat/src/

DESCRIPTION

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ Depends: R (>= 3.1.0)
1212
Imports:
1313
V8,
1414
stringr,
15-
ggplot2
15+
ggplot2 (< 2.2.0)
1616
RoxygenNote: 5.0.1
1717
URL: https://github.com/bhaskarvk/colormap
1818
BugReports: https://github.com/bhaskarvk/colormap/issues
1919
Suggests: scales,
20-
albersusa,
21-
ggalt,
22-
testthat,
23-
ggthemes,
24-
maptools
20+
testthat

README-ggplot2-1.png

134 Bytes
Loading

README-ggplot2-2.png

205 Bytes
Loading

README-maps-1.png

-5.86 KB
Loading

README-maps-2.png

-53.7 KB
Loading

README.Rmd

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ You also get `scale_fill_colormap` and `scale_color_colormap` functions for usin
8989

9090

9191
```{r ggplot2, fig.width=6, fig.height=4}
92+
ensureCranPkg <- function(pkg) {
93+
if(!suppressWarnings(requireNamespace(pkg, quietly = TRUE))) {
94+
install.packages(pkg)
95+
}
96+
}
97+
98+
ensureCranPkg('ggplot2')
99+
92100
library(ggplot2)
93101
94102
# Continuous color scale
@@ -107,6 +115,17 @@ ggplot(mtcars,aes(x=wt,y=mpg)) + geom_point(aes(color=as.factor(cyl))) +
107115
Here are two choroplethes using `scale_fill_colormap`.
108116

109117
```{r maps}
118+
ensureCranPkg('maptools')
119+
ensureCranPkg('scales')
120+
ensureCranPkg('ggplot2')
121+
ensureCranPkg('ggalt')
122+
ensureCranPkg('ggthemes')
123+
ensureCranPkg('devtools')
124+
125+
if(!suppressWarnings(requireNamespace('albersusa', quietly = TRUE))) {
126+
devtools::install_github('hrbrmstr/albersusa')
127+
}
128+
110129
library(maptools)
111130
library(scales)
112131
library(ggplot2)
@@ -116,19 +135,14 @@ library(ggthemes)
116135
library(colormap)
117136
118137
us <- usa_composite()
119-
us_map <- fortify(us, region="name")
120-
121-
gg_usa <- ggplot()
122-
gg_usa <- gg_usa + geom_map(data=us_map, map=us_map,
123-
aes(x=long, y=lat, map_id=id),
124-
color="#2b2b2b", size=0.1, fill=NA)
125-
gg_usa <- gg_usa + theme_map()
126-
gg_usa <- gg_usa +
127-
geom_map(data=us@data, map=us_map,
128-
aes(fill=pop_2014, map_id=name),
129-
color="white", size=0.1) +
138+
us_map <- fortify(us, region="fips_state")
139+
140+
gg_usa <- ggplot(us@data, aes(map_id=fips_state,fill=pop_2014)) +
141+
geom_map(map=us_map, color='#ffffff', size=0.1) +
142+
expand_limits(x=us_map$long,y=us_map$lat) +
143+
theme_map() +
130144
coord_proj(us_laea_proj) +
131-
theme(legend.position="right")
145+
theme(legend.position="right")
132146
133147
gg_usa +
134148
scale_fill_colormap("State Population\n(2014 Estimates)", labels=comma,
@@ -139,16 +153,14 @@ counties <- counties_composite()
139153
140154
counties_map <- fortify(counties, region="fips")
141155
142-
gg_counties <- ggplot()
143-
gg_counties <- gg_counties + geom_map(data=counties_map, map=counties_map,
144-
aes(x=long, y=lat, map_id=id),
145-
color="#2b2b2b", size=0.1, fill=NA)
146-
gg_counties <- gg_counties + theme_map() +
147-
coord_proj(us_laea_proj, xlim = c(-122, -74.5 ))
148-
gg_counties <- gg_counties +
149-
geom_map(data=counties@data, map=counties_map,
150-
aes(fill=population/census_area, map_id=fips),
151-
color="white", size=0.1)
156+
gg_counties <- ggplot(counties@data,
157+
aes(map_id=fips,fill=population/census_area)) +
158+
geom_map(map=counties_map, color='#ffffff', size=0.1) +
159+
expand_limits(x=counties_map$long,y=counties_map$lat) +
160+
theme_map() +
161+
coord_proj(us_laea_proj) +
162+
theme(legend.position="right")
163+
152164
gg_counties +
153165
scale_fill_colormap("County Population Density", labels=comma, trans = 'log10',
154166
colormap = colormaps$picnic, reverse = F, discrete = F) +
@@ -160,6 +172,7 @@ gg_counties +
160172
Here is a plot showing all 44 pre-defined color palettes and the colors they generate.
161173

162174
```{r plot, fig.height=18}
175+
ensureCranPkg('purrr')
163176
par(mfrow=c(44,1))
164177
par(mar=rep(0.25,4))
165178
purrr::walk(colormaps, function(x) {

README.html

Lines changed: 0 additions & 176 deletions
This file was deleted.

README.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ colormap(format='rgbaString',nshades=10) # As rgba string
113113
You also get `scale_fill_colormap` and `scale_color_colormap` functions for using these palettes in ggplot2 plots. Check `?colormap::scale_fill_colormap` for details.
114114

115115
``` r
116+
ensureCranPkg <- function(pkg) {
117+
if(!suppressWarnings(requireNamespace(pkg, quietly = TRUE))) {
118+
install.packages(pkg)
119+
}
120+
}
121+
122+
ensureCranPkg('ggplot2')
123+
116124
library(ggplot2)
117125

118126
# Continuous color scale
@@ -137,31 +145,36 @@ ggplot(mtcars,aes(x=wt,y=mpg)) + geom_point(aes(color=as.factor(cyl))) +
137145
Here are two choroplethes using `scale_fill_colormap`.
138146

139147
``` r
148+
ensureCranPkg('maptools')
149+
ensureCranPkg('scales')
150+
ensureCranPkg('ggplot2')
151+
ensureCranPkg('ggalt')
152+
ensureCranPkg('ggthemes')
153+
ensureCranPkg('devtools')
154+
155+
if(!suppressWarnings(requireNamespace('albersusa', quietly = TRUE))) {
156+
devtools::install_github('hrbrmstr/albersusa')
157+
}
158+
140159
library(maptools)
141160
#> Loading required package: sp
142161
#> Checking rgeos availability: TRUE
143162
library(scales)
144163
library(ggplot2)
145164
library(ggalt)
146-
#> ggalt is under *active* development. See https://github.com/hrbrmstr/ggalt for changes
147165
library(albersusa)
148166
library(ggthemes)
149167
library(colormap)
150168

151169
us <- usa_composite()
152-
us_map <- fortify(us, region="name")
153-
154-
gg_usa <- ggplot()
155-
gg_usa <- gg_usa + geom_map(data=us_map, map=us_map,
156-
aes(x=long, y=lat, map_id=id),
157-
color="#2b2b2b", size=0.1, fill=NA)
158-
gg_usa <- gg_usa + theme_map()
159-
gg_usa <- gg_usa +
160-
geom_map(data=us@data, map=us_map,
161-
aes(fill=pop_2014, map_id=name),
162-
color="white", size=0.1) +
170+
us_map <- fortify(us, region="fips_state")
171+
172+
gg_usa <- ggplot(us@data, aes(map_id=fips_state,fill=pop_2014)) +
173+
geom_map(map=us_map, color='#ffffff', size=0.1) +
174+
expand_limits(x=us_map$long,y=us_map$lat) +
175+
theme_map() +
163176
coord_proj(us_laea_proj) +
164-
theme(legend.position="right")
177+
theme(legend.position="right")
165178

166179
gg_usa +
167180
scale_fill_colormap("State Population\n(2014 Estimates)", labels=comma,
@@ -177,16 +190,14 @@ counties <- counties_composite()
177190

178191
counties_map <- fortify(counties, region="fips")
179192

180-
gg_counties <- ggplot()
181-
gg_counties <- gg_counties + geom_map(data=counties_map, map=counties_map,
182-
aes(x=long, y=lat, map_id=id),
183-
color="#2b2b2b", size=0.1, fill=NA)
184-
gg_counties <- gg_counties + theme_map() +
185-
coord_proj(us_laea_proj, xlim = c(-122, -74.5 ))
186-
gg_counties <- gg_counties +
187-
geom_map(data=counties@data, map=counties_map,
188-
aes(fill=population/census_area, map_id=fips),
189-
color="white", size=0.1)
193+
gg_counties <- ggplot(counties@data,
194+
aes(map_id=fips,fill=population/census_area)) +
195+
geom_map(map=counties_map, color='#ffffff', size=0.1) +
196+
expand_limits(x=counties_map$long,y=counties_map$lat) +
197+
theme_map() +
198+
coord_proj(us_laea_proj) +
199+
theme(legend.position="right")
200+
190201
gg_counties +
191202
scale_fill_colormap("County Population Density", labels=comma, trans = 'log10',
192203
colormap = colormaps$picnic, reverse = F, discrete = F) +
@@ -199,6 +210,9 @@ gg_counties +
199210
Here is a plot showing all 44 pre-defined color palettes and the colors they generate.
200211

201212
``` r
213+
ensureCranPkg('purrr')
214+
#> Installing package into '/opt/user/code/personal/github/colormap/packrat/lib/x86_64-apple-darwin15.6.0/3.3.1'
215+
#> (as 'lib' is unspecified)
202216
par(mfrow=c(44,1))
203217
par(mar=rep(0.25,4))
204218
purrr::walk(colormaps, function(x) {

colormap.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ StripTrailingWhitespace: Yes
1717
BuildType: Package
1818
PackageUseDevtools: Yes
1919
PackageInstallArgs: --no-multiarch --with-keep.source
20+
PackageCheckArgs: --as-cran
2021
PackageRoxygenize: rd,collate,namespace,vignette

0 commit comments

Comments
 (0)