Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Elevation Profiles in R
No Latitude Longitude Altitude Depth Heartrate Cadence Date Time
12649 33.894321 -84.458147 259.7 0.000 2013/01/21 16:06:48
12650 33.894197 -84.457936 259.7 0.000 2013/01/21 16:06:54
12651 33.894092 -84.457788 261.1 0.000 2013/01/21 16:06:59
12652 33.893979 -84.457689 269.3 0.000 2013/01/21 16:07:04
12653 33.893826 -84.457458 272.2 0.000 2013/01/21 16:07:11
12654 33.893603 -84.457440 269.8 0.000 2013/01/21 16:07:16
12655 33.893208 -84.457335 266.9 0.000 2013/01/21 16:07:22
12656 33.893095 -84.457205 268.8 0.000 2013/01/21 16:07:25
12657 33.893032 -84.457152 261.6 0.000 2013/01/21 16:07:27
12658 33.892889 -84.457063 251.5 0.000 2013/01/21 16:07:31
12659 33.892653 -84.456894 245.8 0.000 2013/01/21 16:07:36
12660 33.892491 -84.456720 253.4 0.000 2013/01/21 16:07:41
12661 33.892485 -84.456665 240.5 0.000 2013/01/21 16:07:45
12662 33.892451 -84.456701 238.1 0.000 2013/01/21 16:07:46
12663 33.892332 -84.456660 237.6 0.000 2013/01/21 16:07:48
12664 33.892081 -84.456354 240.9 0.000 2013/01/21 16:07:52
12665 33.892042 -84.456297 244.3 0.000 2013/01/21 16:07:53
12666 33.892002 -84.456291 243.4 0.000 2013/01/21 16:07:56
12667 33.891820 -84.456250 242.4 0.000 2013/01/21 16:08:01
12668 33.891596 -84.456125 244.3 0.000 2013/01/21 16:08:05
12669 33.891256 -84.456005 244.3 0.000 2013/01/21 16:08:10
12670 33.891097 -84.455970 244.3 0.000 2013/01/21 16:08:13
12671 33.890871 -84.455967 246.7 0.000 2013/01/21 16:08:18
12672 33.890744 -84.455925 245.8 0.000 2013/01/21 16:08:21
12673 33.890567 -84.456009 246.2 0.000 2013/01/21 16:08:25
12674 33.890398 -84.456113 242.9 0.000 2013/01/21 16:08:29
12675 33.890361 -84.456390 245.8 0.000 2013/01/21 16:08:32
12676 33.890307 -84.456504 247.2 0.000 2013/01/21 16:08:33
12677 33.890252 -84.456643 246.7 0.000 2013/01/21 16:08:35
12678 33.890158 -84.456798 246.7 0.000 2013/01/21 16:08:38
12679 33.890001 -84.456703 246.2 0.000 2013/01/21 16:08:41
12680 33.889903 -84.456525 248.6 0.000 2013/01/21 16:08:44
12681 33.889852 -84.456301 253.4 0.000 2013/01/21 16:08:50
12682 33.889793 -84.456314 252.0 0.000 2013/01/21 16:08:54
12683 33.889695 -84.456081 259.7 0.000 2013/01/21 16:08:59
12684 33.889672 -84.455959 261.6 0.000 2013/01/21 16:09:02
12685 33.889536 -84.455827 269.8 0.000 2013/01/21 16:09:07
12686 33.889425 -84.455755 265.0 0.000 2013/01/21 16:09:13
12687 33.889288 -84.455717 265.0 0.000 2013/01/21 16:09:18
12688 33.889180 -84.455674 266.4 0.000 2013/01/21 16:09:24
12689 33.889087 -84.455594 276.5 0.000 2013/01/21 16:09:32
12690 33.888942 -84.455541 274.6 0.000 2013/01/21 16:09:39
12691 33.888811 -84.455501 273.6 0.000 2013/01/21 16:09:47
12692 33.888630 -84.455476 269.8 0.000 2013/01/21 16:09:56
12693 33.888426 -84.455434 270.3 0.000 2013/01/21 16:10:04
12694 33.888277 -84.455331 271.7 0.000 2013/01/21 16:10:10
12695 33.888170 -84.455303 272.2 0.000 2013/01/21 16:10:16
12696 33.887990 -84.455242 273.2 0.000 2013/01/21 16:10:25
12697 33.887869 -84.455203 276.0 0.000 2013/01/21 16:10:32
12698 33.887715 -84.455166 276.0 0.000 2013/01/21 16:10:40
12699 33.887533 -84.455125 273.6 0.000 2013/01/21 16:10:48
12700 33.887433 -84.455012 275.6 0.000 2013/01/21 16:10:52
12701 33.887275 -84.454789 279.9 0.000 2013/01/21 16:10:56
12702 33.887225 -84.454738 280.4 0.000 2013/01/21 16:10:57
12703 33.886990 -84.454650 282.8 0.000 2013/01/21 16:11:01
12704 33.886751 -84.454572 280.8 0.000 2013/01/21 16:11:08
12705 33.886673 -84.454560 278.9 0.000 2013/01/21 16:11:14
12706 33.886665 -84.454573 276.5 0.000 2013/01/21 16:11:23
12707 33.886630 -84.454546 283.2 0.000 2013/01/21 16:11:54
12708 33.886685 -84.454683 270.7 0.000 2013/01/21 16:12:20
12709 33.886573 -84.454496 268.3 0.000 2013/01/21 16:12:26
12710 33.886531 -84.454271 264.5 0.000 2013/01/21 16:12:31
12711 33.886486 -84.454146 264.0 0.000 2013/01/21 16:12:34
12712 33.886300 -84.454111 263.5 0.000 2013/01/21 16:12:38
12713 33.886237 -84.454111 263.5 0.000 2013/01/21 16:12:39
12714 33.886041 -84.453942 264.0 0.000 2013/01/21 16:12:43
12715 33.885902 -84.453575 266.4 0.000 2013/01/21 16:12:48
12716 33.885712 -84.453236 265.0 0.000 2013/01/21 16:12:54
12717 33.885604 -84.453114 264.5 0.000 2013/01/21 16:12:57
12718 33.885377 -84.452914 264.0 0.000 2013/01/21 16:13:03
12719 33.885330 -84.452877 264.0 0.000 2013/01/21 16:13:04
12720 33.885020 -84.452644 262.1 0.000 2013/01/21 16:13:10
12721 33.884654 -84.452420 258.7 0.000 2013/01/21 16:13:15
12722 33.884383 -84.452073 258.7 0.000 2013/01/21 16:13:20
12723 33.884170 -84.451778 259.2 0.000 2013/01/21 16:13:25
12724 33.884015 -84.451582 258.7 0.000 2013/01/21 16:13:30
12725 33.883769 -84.451402 256.8 0.000 2013/01/21 16:13:35
12726 33.883508 -84.451295 253.4 0.000 2013/01/21 16:13:40
12727 33.883461 -84.451289 253.0 0.000 2013/01/21 16:13:41
12728 33.883111 -84.451329 247.7 0.000 2013/01/21 16:13:47
12729 33.882785 -84.451389 244.3 0.000 2013/01/21 16:13:52
12730 33.882383 -84.451403 242.4 0.000 2013/01/21 16:13:58
12731 33.882158 -84.451365 240.5 0.000 2013/01/21 16:14:02
12732 33.882055 -84.451335 239.5 0.000 2013/01/21 16:14:04
12733 33.881884 -84.451166 240.5 0.000 2013/01/21 16:14:08
12734 33.881662 -84.450938 247.7 0.000 2013/01/21 16:14:12
12735 33.881400 -84.450839 255.8 0.000 2013/01/21 16:14:16
12736 33.881235 -84.450931 259.2 0.000 2013/01/21 16:14:20
12737 33.881089 -84.451046 253.9 0.000 2013/01/21 16:14:24
12738 33.881021 -84.451117 252.0 0.000 2013/01/21 16:14:26
12739 33.880793 -84.451284 251.0 0.000 2013/01/21 16:14:32
12740 33.880688 -84.451229 249.6 0.000 2013/01/21 16:14:37
12741 33.880651 -84.451156 251.0 0.000 2013/01/21 16:14:39
12742 33.880526 -84.450914 255.4 0.000 2013/01/21 16:14:45
12743 33.880499 -84.450904 257.8 0.000 2013/01/21 16:14:46
12744 33.880362 -84.450942 265.0 0.000 2013/01/21 16:14:49
12745 33.880103 -84.451009 274.1 0.000 2013/01/21 16:14:53
12746 33.879914 -84.450878 267.9 0.000 2013/01/21 16:14:58
12747 33.879869 -84.450858 267.4 0.000 2013/01/21 16:14:59
12748 33.879721 -84.450763 264.0 0.000 2013/01/21 16:15:02
12749 33.879514 -84.450404 265.5 0.000 2013/01/21 16:15:07
12750 33.879367 -84.450078 269.3 0.000 2013/01/21 16:15:11
12751 33.879262 -84.449945 270.3 0.000 2013/01/21 16:15:14
12752 33.879184 -84.449876 270.7 0.000 2013/01/21 16:15:16
12753 33.879136 -84.449840 269.8 0.000 2013/01/21 16:15:18
12754 33.878998 -84.449763 263.1 0.000 2013/01/21 16:15:23
12755 33.878900 -84.449633 257.3 0.000 2013/01/21 16:15:27
12756 33.878871 -84.449611 256.3 0.000 2013/01/21 16:15:28
12757 33.878650 -84.449459 254.4 0.000 2013/01/21 16:15:34
12758 33.878458 -84.449279 253.9 0.000 2013/01/21 16:15:39
12759 33.878380 -84.449212 254.9 0.000 2013/01/21 16:15:41
12760 33.878314 -84.449139 256.3 0.000 2013/01/21 16:15:43
12761 33.878137 -84.449051 256.3 0.000 2013/01/21 16:15:49
12762 33.878099 -84.449011 255.8 0.000 2013/01/21 16:15:51
12763 33.877978 -84.448878 255.8 0.000 2013/01/21 16:15:56
12764 33.877893 -84.448776 253.9 0.000 2013/01/21 16:15:59
12765 33.877727 -84.448576 253.9 0.000 2013/01/21 16:16:04
12766 33.877664 -84.448520 254.4 0.000 2013/01/21 16:16:06
12767 33.877557 -84.448416 253.9 0.000 2013/01/21 16:16:09
12768 33.877324 -84.448177 255.8 0.000 2013/01/21 16:16:14
12769 33.877130 -84.447961 253.0 0.000 2013/01/21 16:16:19
12770 33.877100 -84.447924 252.0 0.000 2013/01/21 16:16:20
12771 33.877040 -84.447874 250.6 0.000 2013/01/21 16:16:23
12772 33.876900 -84.448049 247.2 0.000 2013/01/21 16:16:28
12773 33.876775 -84.448206 240.5 0.000 2013/01/21 16:16:35
12774 33.876774 -84.448188 241.4 0.000 2013/01/21 16:16:43
12775 33.876777 -84.448209 237.1 0.000 2013/01/21 16:16:51
12776 33.876641 -84.448167 236.1 0.000 2013/01/21 16:16:57
12777 33.876461 -84.448171 238.1 0.000 2013/01/21 16:17:03
12778 33.876393 -84.448223 234.2 0.000 2013/01/21 16:17:08
12779 33.876316 -84.448313 227.5 0.000 2013/01/21 16:17:13
12780 33.876251 -84.448521 220.3 0.000 2013/01/21 16:17:17
12781 33.876233 -84.448748 203.5 0.000 2013/01/21 16:17:21
12782 33.876222 -84.448841 196.7 0.000 2013/01/21 16:17:23
12783 33.876157 -84.448991 195.8 0.000 2013/01/21 16:17:27
12784 33.875956 -84.449130 204.9 0.000 2013/01/21 16:17:32
12785 33.875481 -84.449265 223.6 0.000 2013/01/21 16:17:41
12786 33.875235 -84.449430 225.1 0.000 2013/01/21 16:17:47
12787 33.875139 -84.449540 224.6 0.000 2013/01/21 16:17:50
12788 33.875026 -84.449732 223.6 0.000 2013/01/21 16:17:55
12789 33.874834 -84.450095 215.5 0.000 2013/01/21 16:18:03
12790 33.874635 -84.450376 210.7 0.000 2013/01/21 16:18:10
12791 33.874568 -84.450448 211.6 0.000 2013/01/21 16:18:12
12792 33.874426 -84.450632 212.1 0.000 2013/01/21 16:18:17
12793 33.874336 -84.450742 214.5 0.000 2013/01/21 16:18:20
12794 33.874143 -84.450999 216.0 0.000 2013/01/21 16:18:27
12795 33.874046 -84.451146 217.4 0.000 2013/01/21 16:18:31
12796 33.874023 -84.451188 216.9 0.000 2013/01/21 16:18:32
12797 33.873852 -84.451350 226.0 0.000 2013/01/21 16:18:37
12798 33.873740 -84.451531 225.6 0.000 2013/01/21 16:18:42
12799 33.873590 -84.451772 228.0 0.000 2013/01/21 16:18:49
12800 33.873498 -84.451956 224.1 0.000 2013/01/21 16:18:54
12801 33.873315 -84.452185 226.5 0.000 2013/01/21 16:19:01
12802 33.873128 -84.452323 231.3 0.000 2013/01/21 16:19:06
12803 33.872972 -84.452459 229.9 0.000 2013/01/21 16:19:12
12804 33.872807 -84.452560 231.3 0.000 2013/01/21 16:19:16
12805 33.872720 -84.452615 233.3 0.000 2013/01/21 16:19:18
12806 33.872653 -84.452680 231.3 0.000 2013/01/21 16:19:20
12807 33.872536 -84.452868 228.0 0.000 2013/01/21 16:19:27
12808 33.872418 -84.452969 229.4 0.000 2013/01/21 16:19:32
12809 33.872263 -84.453031 229.4 0.000 2013/01/21 16:19:37
12810 33.872089 -84.453089 229.4 0.000 2013/01/21 16:19:42
12811 33.871860 -84.453237 229.9 0.000 2013/01/21 16:19:50
12812 33.871599 -84.453454 230.4 0.000 2013/01/21 16:19:59
12813 33.871403 -84.453644 229.9 0.000 2013/01/21 16:20:06
12814 33.871233 -84.453718 228.0 0.000 2013/01/21 16:20:11
gps <- read.csv("callan.csv",
header = TRUE)
# calculate moving average: (this section is optional)
library(TTR)
movingN <- 5 # define the n for the moving average calculations
gps$Altitude <- gps$Altitude * 3.281 # convert m to ft
gps$SMA <- SMA(gps$Altitude,
n = movingN)
gps <- gps[movingN:length(gps$SMA), ] # remove first n-1 points
# calculate distances, if not included in your dataset:
library(sp)
Dist <- 0
for(i in 2:length(gps$Longitude)) {
Dist[i] = spDistsN1(as.matrix(gps[i,c("Longitude", "Latitude")]),
c(gps$Longitude[i-1], gps$Latitude[i-1]),
longlat = TRUE) / 1.609 # longlat so distances will be in km, then divide to convert to miles
}
gps$Dist <- Dist
DistTotal <- 0
for(i in 2:length(gps$Longitude)) {
DistTotal[i] = Dist[i] + DistTotal[i-1]
}
gps$DistTotal <- DistTotal
# plot:
library(ggplot2)
ggplot(gps, aes(x = DistTotal)) +
geom_ribbon(aes(ymin = 600, # change this to match your min below
ymax = SMA),
fill = "#1B9E77") + # put your altitude variable here if not using moving averages
labs(x = "Miles",
y = "Elevation") +
scale_y_continuous(limits = c(600,1200)) # change this to limits appropriate for your region
gps <- read.csv("callan.csv",
header = TRUE)
# calculate moving average: (this section is optional)
library(TTR)
movingN <- 5 # define the n for the moving average calculations
gps$SMA <- SMA(gps$Altitude,
n = movingN)
gps <- gps[movingN:length(gps$SMA), ] # remove first n-1 points
# calculate distances, if not included in your dataset:
library(sp)
Dist <- 0
for(i in 2:length(gps$Longitude)) {
Dist[i] = spDistsN1(as.matrix(gps[i,c("Longitude", "Latitude")]),
c(gps$Longitude[i-1], gps$Latitude[i-1]),
longlat = TRUE) # longlat so distances will be in km
}
gps$Dist <- Dist
DistTotal <- 0
for(i in 2:length(gps$Longitude)) {
DistTotal[i] = Dist[i] + DistTotal[i-1]
}
gps$DistTotal <- DistTotal
# plot:
library(ggplot2)
ggplot(gps, aes(x = DistTotal)) +
geom_ribbon(aes(ymin = 180, # change this to match your min below
ymax = SMA),
fill = "#1B9E77") + # put your altitude variable here if not using moving averages
labs(x = "Distance, km",
y = "Elevation, m") +
scale_y_continuous(limits = c(180,360)) # change this to limits appropriate for your region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment