Skip to content

Instantly share code, notes, and snippets.

View josephlewis's full-sized avatar

josephlewis

View GitHub Profile
@josephlewis
josephlewis / README.md
Last active May 23, 2017 23:01
The 100 greatest British novels
ggplot() + geom_line(data = visits_1, aes(month, visits, group = 1,colour = "#008FD5", size=2)) + facet_wrap(~visits_1$year) + geom_line(data = x, aes(Month, Visits))
str(visits_1)
'data.frame': 164 obs. of 6 variables:
$ museum: chr "NATIONAL GALLERY" "NATIONAL GALLERY" "NATIONAL GALLERY" "NATIONAL GALLERY" ...
$ year : chr "2004" "2004" "2004" "2004" ...
$ month : chr "4" "5" "6" "7" ...
$ visits: num 437000 391000 319000 460000 443000 325000 425000 448000 410000 402000 ...
$ season: chr "" "" "" "" ...
$ date : Date, format: "2004-04-01" "2004-05-01" "2004-06-01" "2004-07-01" ...
ggplot(data = df.m, aes(x = month, group = 1)) +
geom_ribbon(data= subset(df.m, df.m$visits.raw > df.m$visits.mean), aes(ymin = pmin(visits.mean, visits.raw), ymax = pmax(visits.mean, visits.raw)),fill="#008FD5", alpha="0.2") +
geom_line(aes(y = visits.mean), size = 1.5, color = 'grey') +
geom_line(aes(y = visits.raw), size = 1.5, colour = "#008FD5") +
facet_wrap(~year, ncol = 3) +
scale_x_discrete(limits = month.abb) +
scale_y_continuous(labels=comma)
[1] "month"
[2] "visits"
[3] "tmax"
[4] "tmin"
[5] "rainfall"
[6] "OS.visits.to.UK.Earnings..Â..Millions.NSA"
[7] "OS.visits.to.UK.All.visits.Thousands.NSA"
[8] "season"
xx$band[xx$dav_hue_vector >= (0/12) & xx$dav_hue_vector <= (1/12)] <- "Red"
xx$band[xx$dav_hue_vector > (1/12) & xx$dav_hue_vector <= (2/12)] <- "Red-Orange"
xx$band[xx$dav_hue_vector > (2/12) & xx$dav_hue_vector <= (3/12)] <- "Orange"
xx$band[xx$dav_hue_vector > (3/12) & xx$dav_hue_vector <= (4/12)] <- "Yellow-Orange"
xx$band[xx$dav_hue_vector > (4/12) & xx$dav_hue_vector <= (5/12)] <- "Yellow"
xx$band[xx$dav_hue_vector > (5/12) & xx$dav_hue_vector <= (6/12)] <- "Yellow-Green"
xx$band[xx$dav_hue_vector > (6/12) & xx$dav_hue_vector <= (7/12)] <- "Green"
xx$band[xx$dav_hue_vector > (7/12) & xx$dav_hue_vector <= (8/12)] <- "Blue-Green"
xx$band[xx$dav_hue_vector > (8/12) & xx$dav_hue_vector <= (9/12)] <- "Blue"
xx$band[xx$dav_hue_vector > (9/12) & xx$dav_hue_vector <= (10/12)] <- "Blue-Violet"
for (i in 1:(nrow(road_coords)/2)) {
A <- unlist(road_coords[i,2:3])
B <- unlist(road_coords[i + 1,2:3])
> head(road_coords)
Name coords.x1 coords.x2
1 Margary 62aa 300409.3 229884.3
2 Margary 62aa 303385.8 231078.0
3 Margary 62b 300419.3 229884.6
road_pts <- list()
for (i in unique(wales_roads$Name)) {
known_pts <- gInterpolate(wales_roads[wales_roads$Name == i,], d = seq(0, gLength(wales_roads[wales_roads$Name == i,]), by = gLength(wales_roads[wales_roads$Name == i,])), normalized = FALSE)
known_pts@coords
A <- known_pts@coords[1,]
B <- known_pts@coords[2,]
AtoB <- shortestPath(Conductance, A, B, output="SpatialLines")
plot(AtoB, add = TRUE, col = "red")
LCP_pts <- gInterpolate(AtoB, d = seq(0, gLength(AtoB), by = 250), normalized = FALSE)
for (i in levels(scot_battles_centroid_dates$century)) { # the levels are "1200s" to "1900s"
battle_road_dist <- gDistance(scot_battles_centroid_dates[scot_battles_centroid_dates$century == i,], sp, byid = TRUE) # euclidean distance from battle point to road.
battle_road_dist_vect <- data.frame(as.vector(battle_road_dist)) # creates df of the distances
dist_test <- rbind(battle_road_dist_vect) # adds to a df to create one df with all of the distances
}
> head(xtestbuffer)
battlefield.no distance decade
1200s NA 1000 1200s
1300s 0.20000000 1000 1300s
1400s NA 1000 1400s
1500s NA 1000 1500s
1600s 0.05882353 1000 1600s
1700s 0.20000000 1000 1700s
decbuf <- ggplot(xtestbuffer) +
plaques$sex[grep("man", plaques$subjects, fixed = TRUE)] <- "Man"
plaques$sex[grep("woman", plaques$subjects, fixed = TRUE)] <- "Woman"