head(EuStockMarkets)
A matrix: 6 × 4 of type dbl
DAXSMICACFTSE
1628.751678.11772.82443.6
1613.631688.51750.52460.2
1606.511678.61718.02448.2
1621.041684.11708.12470.4
1618.161686.61723.12484.7
1610.611671.61714.32466.8
plot(EuStockMarkets)
class(EuStockMarkets)
<ol class=list-inline>
  • 'mts'
  • 'ts'
  • 'matrix'
  • </ol>
    frequency(EuStockMarkets)
    
    260
    start(EuStockMarkets)
    end(EuStockMarkets)
    
    <ol class=list-inline>
  • 1991
  • 130
  • </ol>
    <ol class=list-inline>
  • 1998
  • 169
  • </ol>
    window(EuStockMarkets, start = 1997, end = 1998)
    
    A Time Series: 261 × 4
    DAXSMICACFTSE
    1997.0002844.093869.82289.64092.5
    1997.0042844.093869.82289.64092.5
    1997.0082844.093869.82303.84092.5
    1997.0122859.223922.22307.04091.0
    1997.0152880.073948.32318.64115.7
    1997.0192880.073942.22315.74118.5
    1997.0232880.073942.22315.74118.5
    1997.0272820.813942.22257.04057.4
    1997.0312863.263940.12282.84089.5
    1997.0352890.203923.82306.74106.5
    1997.0382876.343922.92301.74078.8
    1997.0422904.083944.92331.64087.5
    1997.0462936.693966.22349.14087.0
    1997.0502915.813947.42327.54056.6
    1997.0542956.783975.52361.34107.3
    1997.0582978.843983.62402.14168.2
    1997.0622976.563979.62388.04158.9
    1997.0652996.124007.12407.84197.5
    1997.0693006.874019.92425.14207.7
    1997.0732999.194009.52406.14194.0
    1997.0773000.664023.12409.94195.5
    1997.0813026.634115.42442.54219.1
    1997.0853037.284161.02461.34219.1
    1997.0882982.634125.52430.34218.8
    1997.0922992.554127.32435.24212.0
    1997.0963028.274182.32482.84237.4
    1997.1002997.954169.72465.04207.5
    1997.1043018.584209.12503.14228.4
    1997.1083037.704272.22516.64275.8
    1997.1123064.704282.82508.64257.8
    1997.1153067.484296.52503.14260.9
    1997.1193114.734305.52541.34281.5
    1997.1233124.784309.82558.44265.9
    1997.1273161.364357.92597.54307.8
    1997.1313185.724384.32595.44307.7
    1997.1353191.454408.42582.14304.3
    1997.1383211.014444.12599.34304.3
    1997.1423256.864436.32628.44327.1
    1997.1463249.174464.22627.44341.0
    1997.1503260.304514.62634.54337.8
    1997.1543230.834490.72617.54332.3
    1997.1583209.044525.52594.84357.4
    1997.1623197.094530.82575.24356.1
    1997.1653203.794522.52562.84336.8
    1997.1693180.634463.22567.94331.1
    1997.1733233.344503.92607.74344.7
    1997.1773245.024539.02602.24329.3
    1997.1813272.584519.72629.44339.2
    1997.1853261.044487.62607.84308.3
    1997.1883258.744460.12600.34307.1
    1997.1923345.094513.72651.74357.7
    1997.1963375.454547.12666.24360.1
    1997.2003396.554605.22698.94399.3
    1997.2043419.514638.92708.34420.3
    1997.2083426.774684.42709.24437.4
    1997.2123430.954677.12686.24444.3
    1997.2153382.404676.22641.74422.5
    1997.2193367.824609.92632.14397.7
    1997.2233404.294636.22645.64424.3
    1997.2273337.114556.52588.44373.3
    1997.2313289.594519.92574.04356.8
    1997.2353305.724535.12596.84332.2
    1997.2383247.034442.92553.74258.1
    1997.2423288.524491.32587.14254.8
    1997.2463302.574497.32579.34214.8
    1997.2503374.934558.62624.34270.7
    1997.2543439.224620.52648.74301.5
    1997.2583407.834659.22656.74312.9
    1997.2623407.834659.22656.74312.9
    1997.2653407.834659.22656.74312.9
    1997.2693281.464501.72581.84248.1
    1997.2733210.944488.72530.34236.6
    1997.2773212.824463.92514.54214.6
    1997.2813235.354471.52518.04236.6
    1997.2853342.774588.02572.34271.7
    1997.2883328.134582.62579.04269.3
    1997.2923364.764634.92617.64292.3
    1997.2963352.584626.62608.04313.2
    1997.3003319.244604.22574.64270.7
    1997.3043297.524586.32566.14251.7
    1997.3083369.264643.42620.64286.8
    1997.3123347.544625.62621.04294.6
    1997.3153361.804665.72615.24298.9
    1997.3193361.204699.12547.64310.5
    1997.3233328.414740.12522.74328.7
    1997.3273348.904752.32514.74346.1
    1997.3313366.874781.12533.64387.7
    1997.3353396.494836.12539.84388.5
    1997.3383357.574772.32536.34369.7
    1997.3423372.964793.32550.34389.7
    1997.3463425.864855.12602.94433.2
    1997.3503438.094897.62639.54436.0
    1997.3543438.094897.62639.54445.0
    1997.3583491.084953.52655.34455.6
    1997.3623565.695029.62672.84455.6
    1997.3653548.524988.42651.94519.3
    1997.3693537.455016.02643.34537.5
    1997.3733537.455016.02643.34580.4
    1997.3773533.215004.72633.94630.9
    1997.3813593.145042.52693.14669.6
    1997.3853559.295084.22719.64691.0
    1997.3883588.575134.32774.64686.9
    1997.3923564.855141.72776.04681.2
    1997.3963569.265157.52784.34693.9
    1997.4003569.265157.52784.34645.2
    1997.4043516.205081.02751.14607.5
    1997.4083600.405178.62786.44642.0
    1997.4123575.445176.42741.74651.8
    1997.4153621.725181.02762.94661.8
    1997.4193669.315196.72654.74661.8
    1997.4233665.435190.02680.34681.6
    1997.4273626.605133.12583.24677.5
    1997.4313635.385132.12579.24672.3
    1997.4353562.735041.62583.94621.3
    1997.4383596.405150.02601.54562.8
    1997.4423655.595207.22624.54557.8
    1997.4463651.595238.52635.44557.1
    1997.4503684.605251.22690.94576.2
    1997.4543700.535320.02719.34645.0
    1997.4583668.615368.82686.24686.7
    1997.4623671.165361.92664.24739.6
    1997.4653671.875308.62696.24724.8
    1997.4693737.165364.22760.34757.4
    1997.4733752.375384.62808.54783.1
    1997.4773750.025362.02795.94745.1
    1997.4813721.185345.92762.64682.2
    1997.4853730.565405.02751.74657.0
    1997.4883777.565510.32739.74653.7
    1997.4923788.545561.82757.14593.9
    1997.4963748.795587.82762.24575.8
    1997.5003761.075576.12784.84596.3
    1997.5043819.525662.42867.44640.0
    1997.5083820.165669.92893.64657.9
    1997.5123809.925700.32891.04640.3
    1997.5153766.895620.62858.34604.6
    1997.5193834.845654.82944.04728.3
    1997.5233867.535674.32909.54751.4
    1997.5273939.735804.92937.04831.7
    1997.5313946.735846.52934.54812.8
    1997.5354003.355947.02947.74810.7
    1997.5384030.106012.62929.84758.5
    1997.5424026.975977.12950.64762.4
    1997.5464000.655885.42929.14767.8
    1997.5504074.305801.52941.64799.5
    1997.5544142.195845.82941.64857.4
    1997.5584139.685844.72950.74899.3
    1997.5624223.695927.52988.04964.2
    1997.5654203.915868.32958.64949.0
    1997.5694131.945737.12876.74877.2
    1997.5734139.965620.52874.14805.7
    1997.5774297.645677.12921.14846.7
    1997.5814384.825869.93003.54874.5
    1997.5854320.525849.22973.54862.9
    1997.5884368.545847.03025.94851.5
    1997.5924400.305888.03022.24862.6
    1997.5964377.705842.13023.64876.6
    1997.6004458.665929.53069.34927.3
    1997.6044405.525898.23075.74907.5
    1997.6084336.985898.23049.54899.3
    1997.6124302.505771.02992.44895.7
    1997.6154325.865765.22984.14960.6
    1997.6194364.255812.13037.15026.2
    1997.6234428.085922.13056.35086.8
    1997.6274342.315864.82996.35031.3
    1997.6314333.155825.62983.45031.9
    1997.6354377.515808.42998.65075.8
    1997.6384237.065682.12924.05003.6
    1997.6424195.535579.52921.84991.3
    1997.6464077.595498.52921.84865.8
    1997.6504080.555405.62870.14835.0
    1997.6544190.455580.12936.24914.2
    1997.6584251.935690.12979.34958.4
    1997.6624204.815668.82957.24978.0
    1997.6654090.145475.82904.24901.1
    1997.6694076.755473.92898.64901.1
    1997.6733993.705363.32869.34886.3
    1997.6773992.035409.62871.74906.9
    1997.6813897.435217.32828.44845.4
    1997.6853919.795216.72770.54817.5
    1997.6884001.815271.52805.84870.2
    1997.6924127.285447.52921.24952.2
    1997.6964062.135478.62918.04976.9
    1997.7004093.435478.12927.04991.3
    1997.7044073.715532.92924.54994.2
    1997.7084131.265505.32940.94985.2
    1997.7124104.575445.12919.74950.5
    1997.7154028.005356.72874.64905.2
    1997.7193890.245280.82843.64854.8
    1997.7233796.615281.92834.14848.2
    1997.7273869.535321.72898.64902.9
    1997.7313995.695417.82940.64976.4
    1997.7353970.445550.42944.05013.1
    1997.7384004.045629.02978.45046.2
    1997.7423983.065611.02977.25023.8
    1997.7464096.855705.13017.55075.7
    1997.7504091.775730.42997.25027.5
    1997.7544150.955732.53023.75077.2
    1997.7584104.935667.13005.45065.5
    1997.7624135.095716.62985.65226.3
    1997.7654116.525691.82989.05220.3
    1997.7694154.895673.63008.35244.2
    1997.7734262.985754.73054.95317.1
    1997.7774266.175825.03052.15296.1
    1997.7814266.175929.03094.05330.8
    1997.7854326.355897.43078.05300.0
    1997.7884311.135846.93064.45305.6
    1997.7924267.405822.33024.15262.1
    1997.7964179.925732.22960.75217.8
    1997.8004164.625699.52955.15227.3
    1997.8044225.275792.83002.95300.1
    1997.8084215.235836.33002.55298.9
    1997.8124168.625815.92992.25263.7
    1997.8154149.925806.82992.95287.9
    1997.8194049.165751.62958.05271.1
    1997.8234069.255777.22946.75211.0
    1997.8274172.475862.92989.95225.9
    1997.8314124.865803.22958.15148.8
    1997.8353976.385651.82856.94991.5
    1997.8383981.445689.52849.04970.2
    1997.8423871.395533.52769.64840.7
    1997.8463645.695279.72651.34755.4
    1997.8503806.665479.02818.04871.8
    1997.8543748.885370.92739.54801.9
    1997.8583753.665467.22739.34842.3
    1997.8623847.735581.62788.04906.4
    1997.8653784.805538.22774.94897.4
    1997.8693841.395601.62822.44908.3
    1997.8733813.885557.42781.84863.8
    1997.8773715.385438.62707.14764.3
    1997.8813728.375459.72707.14806.8
    1997.8853734.795483.92707.14793.7
    1997.8883697.485434.02694.54720.4
    1997.8923701.945418.22700.74711.0
    1997.8963676.655437.02698.94741.8
    1997.9003816.715565.02773.04867.0
    1997.9043844.145574.22782.64845.4
    1997.9083876.905571.72790.64830.1
    1997.9123931.815650.42821.24908.4
    1997.9153941.915725.52861.74985.8
    1997.9193832.105645.72802.54898.6
    1997.9233850.145666.32786.34863.5
    1997.9273926.935738.32811.74891.2
    1997.9313961.975772.42829.04889.0
    1997.9353972.085775.92854.44831.8
    1997.9384125.925875.12918.54921.8
    1997.9424096.405919.92913.14977.6
    1997.9464074.555922.72902.44970.7
    1997.9504159.725969.52914.55082.3
    1997.9544191.816009.02910.15142.9
    1997.9584208.146095.32932.55187.4
    1997.9624187.136103.22959.45177.1
    1997.9654116.706056.62932.25130.7
    1997.9694016.706021.82828.55035.9
    1997.9734061.916018.72830.35045.2
    1997.9774029.085986.62838.35121.8
    1997.9814150.316092.72912.25203.4
    1997.9854154.576122.12893.35190.8
    1997.9884162.926115.12894.55168.3
    1997.9924055.355989.92822.95020.2
    1997.9964125.546049.32869.75018.2
    1998.0004132.796044.72858.15049.8
    hist(     EuStockMarkets[, "SMI"], 30)
    hist(diff(EuStockMarkets[, "SMI"], 30))
    
    plot(     EuStockMarkets[, "SMI"],       EuStockMarkets[, "DAX"]) 
    plot(diff(EuStockMarkets[, "SMI"]), diff(EuStockMarkets[, "DAX"]))
    
    plot(lag(diff(EuStockMarkets[, "SMI"]), 1), 
             diff(EuStockMarkets[, "DAX"])) 
    
    ## rnorm 함수로 정규분포를 따르는 난수를 100개 추출합니다
    x  <- rnorm(n=100, mean=0, sd=10) + 1:100
    
    ## rep 함수로 1/n 값을 n번 반복하는 배열을 만드는 함수를 만듭니다
    mn <- function(n) rep(1/n, n)
    					
    plot(x, type = 'l', lwd = 1)
    
    ## 기본 R의 filter 함수로 롤링 평균을 계산합니다. 각각 5개, 50개 단위로 롤링 합니다
    lines(filter(x, mn( 5)), col = 2, lwd = 3, lty = 2) 
    lines(filter(x, mn(50)), col = 3, lwd = 3, lty = 3)
    
    ## 기능을 좀 더 '사용자 정의'하여 사용할 수도 있습니다.
    install.packages("zoo")
    require(zoo)
    
    ## x를 zoo 객체로 만들어 각 데이터를 인덱싱 해 줍니다
    ## rollapply 함수는 데이터, 윈도우크기, 적용함수, 롤링적용 정렬 방향, 
    ## 윈도우크기만큼 데이터가 없어도 적용할 것인가? 등의 인자 값을 지정합니다
    f1 <- rollapply(zoo(x), 20, function(w) min(w),				
                    align = "left", partial = TRUE) 
    f2 <- rollapply(zoo(x), 20, function(w) min(w), 
                    align = "right", partial = TRUE)
    					
    plot(x, lwd=1, type='l') 
    lines(f1, col=2, lwd=3, lty=2) 
    lines(f2, col=3, lwd=3, lty=3) 
    
    Installing package into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    Loading required package: zoo
    
    
    Attaching package: ‘zoo’
    
    
    The following objects are masked from ‘package:base’:
    
        as.Date, as.Date.numeric
    
    
    
    # 확장 윈도우
    plot(x, type = 'l', lwd = 1)
    lines(cummax(x), col = 2, lwd = 3, lty = 2) # 최대값 
    lines(cumsum(x)/1:length(x), col = 3, lwd = 3, lty = 3) # 평균
    
    plot(x, type = 'l', lwd = 1)
    lines(rollapply(zoo(x), seq_along(x), function(w) max(w),
                            partial = TRUE, align = "right"),
              col=2,lwd=3,lty=2)
    lines(rollapply(zoo(x), seq_along(x), function(w) mean(w), 	
                            partial = TRUE, align = "right"),			 
              col=2,lwd=3,lty=3)
    
    x<-1:100 
    y<-sin(x * pi /3) 
    plot(y, type = "b") 
    acf(y) 
    
    install.packages("data.table")
    library(data.table)
    
    Installing package into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    
    ## cor 함수는 상관계수를 계산하는 용도로 사용됩니다
    ## 첫 번째와 두 번째 파라미터가 비교 대상 둘에 대한 것입니다
    ## use 파라미터는 누락된 값 처리 방법으로, pairwise.complete.obs는
    ## 계산 대상 변수만을 대상으로 누락된 값을 제거합니다
    ## y와 y로부터 시차 1과 2만큼 움직인 것과의 상관계수를 계산합니다
    cor(y, shift(y, 1), use = "pairwise.complete.obs")
    cor(y, shift(y, 2), use = "pairwise.complete.obs")
    
    0.500153115912332
    -0.503715197153103
    y<-sin(x * pi /3)
    plot(y[1:30], type = "b") 
    pacf(y) 
    
    y1<-sin(x * pi /3) 
    plot(y1, type = "b") 
    acf (y1)
    pacf(y1)
    					
    y2<-sin(x * pi /10) 
    plot(y2, type = "b") 
    acf (y2)
    pacf(y2) 
    
    y <- y1 + y2
    plot(y, type = "b") 
    acf (y)
    pacf(y)
    
    ## R
    noise1 <- rnorm(100, sd = 0.05)
    noise2 <- rnorm(100, sd = 0.05)
    					
    y1 <- y1 + noise1 
    y2 <- y2 + noise2 
    y  <- y1 + y2
    					
    plot(y1, type = 'b')
    acf (y1)
    pacf(y1)
    					
    plot(y2, type = 'b')
    acf (y2)
    pacf(y2)
    					
    plot(y, type = 'b')
    acf (y)
    pacf(y)		
    
    ## R
    x <- 1:100
    plot(x)
    acf (x)
    pacf(x)
    
    install.packages("timevis")
    require(timevis)				
    donations <- fread("donations.csv")
    d <- donations[, .(min(timestamp), max(timestamp)), user]
    names(d) <- c("content", "start", "end")
    d <- d[start != end]
    timevis(d[sample(1:nrow(d), 20)])
    
    Installing package into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    also installing the dependencies ‘httpuv’, ‘xtable’, ‘sourcetools’, ‘fastmap’, ‘shiny’
    
    
    Loading required package: timevis
    
    
    Error in fread("donations.csv"): File 'donations.csv' does not exist or is non-readable. getwd()=='/content'
    Traceback:
    
    1. fread("donations.csv")
    2. stop("File '", file, "' does not exist or is non-readable. getwd()=='", 
     .     getwd(), "'")
    t(matrix(AirPassengers, nrow = 12, ncol = 12))
    
    A matrix: 12 × 12 of type dbl
    112118132129121135148148136119104118
    115126141135125149170170158133114140
    145150178163172178199199184162146166
    171180193181183218230242209191172194
    196196236235229243264272237211180201
    204188235227234264302293259229203229
    242233267269270315364347312274237278
    284277317313318374413405355306271306
    315301356348355422465467404347305336
    340318362348363435491505404359310337
    360342406396420472548559463407362405
    417391419461472535622606508461390432
    ## R				
    colors<-c("green","red", "pink", "blue",
              "yellow","lightsalmon", "black", "gray",
              "cyan", "lightblue",  "maroon", "purple")
    matplot(matrix(AirPassengers, nrow = 12, ncol = 12),
              type = 'l', col = colors, lty = 1, lwd = 2.5,
              xaxt = "n", ylab = "Passenger Count") 
    legend("topleft", legend = 1949:1960, lty = 1, lwd = 2.5,
             col = colors)
    axis(1, at = 1:12, labels = c("Jan", "Feb", "Mar", "Apr",
                                  "May", "Jun", "Jul", "Aug",
                                  "Sep", "Oct", "Nov", "Dec"))	
    
    install.packages("forecast")
    require(forecast)
    seasonplot(AirPassengers)
    
    Installing package into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    also installing the dependencies ‘xts’, ‘TTR’, ‘quadprog’, ‘quantmod’, ‘fracdiff’, ‘lmtest’, ‘timeDate’, ‘tseries’, ‘urca’, ‘RcppArmadillo’
    
    
    Loading required package: forecast
    
    Registered S3 method overwritten by 'quantmod':
      method            from
      as.zoo.data.frame zoo 
    
    
    ## R			
    months <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", 
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    					
    matplot(t(matrix(AirPassengers, nrow = 12, ncol = 12)), 
                type='l',col=colors,lty=1,lwd=2.5) 
    legend("left", legend = months,
                            col=colors,lty=1,lwd=2.5) 
    
     monthplot(AirPassengers)
    
    hist2d <- function(data, nbins.y, xlabels) { 
      ## we make ybins evenly spaced to include 
      ## minimum and maximum points
      ymin=min(data)				
      ymax=max(data) * 1.0001
      ## the lazy way out to avoid worrying about inclusion/exclusion
    					
      ybins=seq(from=ymin,to=ymax,length.out=nbins.y+1) 
      ## make a zero matrix of the appropriate size
      hist.matrix=matrix(0,nrow=nbins.y,ncol=ncol(data))
    
      ## data comes in matrix form where each row 
      ## represents one data point 
      for(i in 1:nrow(data)) {
         ts = findInterval(data[i, ], ybins)
         for (j in 1:ncol(data)) {
           hist.matrix[ts[j], j] = hist.matrix[ts[j], j] + 1 hist.matrix
         }
      }
      hist.matrix
    }	
    
    h <- hist2d(t(matrix(AirPassengers, nrow = 12, ncol = 12)), 5, months) 
    
    Error in hist.matrix[ts[j], j] <- hist.matrix[ts[j], j] + 1 > hist.matrix: number of items to replace is not a multiple of replacement length
    Traceback:
    
    1. hist2d(t(matrix(AirPassengers, nrow = 12, ncol = 12)), 5, months)
    image(1:ncol(h), 1:nrow(h), t(h), col = heat.colors(5), axes = FALSE, xlab = "Time", ylab = "Passenger Count") 
    
    Error in ncol(h): object 'h' not found
    Traceback:
    
    1. image(1:ncol(h), 1:nrow(h), t(h), col = heat.colors(5), axes = FALSE, 
     .     xlab = "Time", ylab = "Passenger Count")
    2. ncol(h)
    require(data.table)
    
    words <- fread(url.str)
    w1 <- words[V1 == 1]
    h = hist2d(w1, 25, 1:ncol(w1))					
    					 					
    colors <- gray.colors(20, start = 1, end = .5)
    par(mfrow = c(1, 2))
    image(1:ncol(h), 1:nrow(h), t(h),
          col = colors, axes = FALSE, xlab = "Time", ylab = "Projection Value") 
    image(1:ncol(h), 1:nrow(h), t(log(h)),
          col = colors, axes = FALSE, xlab = "Time", ylab = "Projection Value") 	
    
    Error in fread(url.str): object 'url.str' not found
    Traceback:
    
    1. fread(url.str)
    ## R					
    w1 <- words[V1 == 1]
    				
    ## melt the data to the pairs of paired-coordinates 
    ## expected by most 2d histogram implementations
    names(w1) <- c("type", 1:270)
    w1 <- melt(w1, id.vars = "type")
    					
    w1 <- w1[, -1]
    names(w1) <- c("Time point", "Value")				
    plot(hexbin(w1))
    
    devtools::install_github('IRkernel/repr')
    
    Downloading GitHub repo IRkernel/repr@HEAD
    
    
    glue  (1.4.1 -> 1.4.2) [CRAN]
    vctrs (0.3.2 -> 0.3.4) [CRAN]
    
    Installing 2 packages: glue, vctrs
    
    Installing packages into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    
      checking for file ‘/tmp/RtmpnGpW8u/remotes654a01c9f6/IRkernel-repr-7baa0ae/DESCRIPTION’
      preparing ‘repr’:
      checking DESCRIPTION meta-information
      checking for LF line-endings in source and make files and shell scripts
      checking for empty or unneeded directories
      building ‘repr_1.1.1.9000.tar.gz’
       
    
    Installing package into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    
    install.packages(c('repr', 'IRdisplay', 'pbdZMQ', 'devtools'))
    
    Installing packages into ‘/usr/local/lib/R/site-library’
    (as ‘lib’ is unspecified)
    
    
    # install.packages("plotly")
    require(plotly)
    require(data.table)
    					
    months = 1:12
    ap = data.table(matrix(AirPassengers, nrow = 12, ncol = 12))
    names(ap) = as.character(1949:1960) 
    ap[, month := months]
    ap = melt(ap, id.vars = 'month')
    names(ap) = c("month", "year", "count")
    				
    p <- plot_ly(ap, x = ~month, y = ~year, z = ~count, 
                 color = ~as.factor(month)) %>%	
      add_markers()%>% 
      layout(scene=list(xaxis = list(title = 'Month'),
                        yaxis = list(title = 'Year'),
                        zaxis = list(title = 'PassengerCount')))	
    
    embed_notebook(p)
    
    Warning message in RColorBrewer::brewer.pal(N, "Set2"):
    “n too large, allowed maximum for palette Set2 is 8
    Returning the palette you asked for with that many colors
    ”
    
    Error in farver::decode_colour(colors, alpha = TRUE, to = "lab", na_value = "transparent"): unused argument (na_value = "transparent")
    Traceback:
    
    1. embed_notebook(p)
    2. embed_notebook.plotly(p)
    3. plotly_build(x)
    4. plotly_build.plotly(x)
    5. map_color(traces, title = paste(colorTitle, collapse = br()), 
     .     colorway = colorway(p))
    6. Map(function(x, y) toRGB(colScale(as.character(x)), y), color[isDiscrete], 
     .     alphas[isDiscrete])
    7. mapply(FUN = f, ..., SIMPLIFY = FALSE)
    8. (function (x, y) 
     . toRGB(colScale(as.character(x)), y))(dots[[1L]][[1L]], dots[[2L]][[1L]])
    9. toRGB(colScale(as.character(x)), y)
    10. colScale(as.character(x))
    11. safePaletteFunc(palette, na.color, alpha, nlevels = length(lvls) * 
      .     ifelse(reverse, -1, 1))
    12. filterRange(filterNA(na.color = na.color, filterZeroLength(filterRGB(toPaletteFunc(pal, 
      .     alpha = alpha, nlevels = nlevels)))))
    13. force(f)
    14. filterNA(na.color = na.color, filterZeroLength(filterRGB(toPaletteFunc(pal, 
      .     alpha = alpha, nlevels = nlevels))))
    15. force(f)
    16. filterZeroLength(filterRGB(toPaletteFunc(pal, alpha = alpha, 
      .     nlevels = nlevels)))
    17. force(f)
    18. filterRGB(toPaletteFunc(pal, alpha = alpha, nlevels = nlevels))
    19. force(f)
    20. toPaletteFunc(pal, alpha = alpha, nlevels = nlevels)
    21. toPaletteFunc.character(pal, alpha = alpha, nlevels = nlevels)
    22. colour_ramp(colors, alpha = alpha)
    file.location <- 'https://raw.githubusercontent.com/plotly/datasets/master/_3d-line-plot.csv'	
    data <- read.csv(file.location) 
    p <- plot_ly(data,x=~x1,y=~y1,z=~z1,
                    type = 'scatter3d', mode = 'lines',
                    line = list(color = '#1f77b4', width = 1))	
    
    embed_notebook(p)