This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
You can also embed plots, for example:
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggplot2)
trace1 <- list(
x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011),
y = c(11.001, 11.001, 18.335, 22.002, 18.335, 22.002, 25.669, 916.75, 1243.113, 20524.199, 15247.386, 21184.259, 23454.132, 30630.451, 31327.181, 31070.491, 39651.271, 38785.859, 44814.407, 36607.661, 36904.688, 36857.017, 36871.685, 35342.546, 46394.884, 49926.205, 47234.627, 47693.002, 48367.73, 54487.953, 52009.061, 57010.849, 58136.618, 65980.331, 73130.981, 70641.088, 41059.399, 41646.119, 81495.408, 78374.791, 112562.232, 101414.552, 84704.033, 106841.712, 113240.627, 116148.558, 123874.927, 139404.672, 158935.114, 162602.114, 167596.568, 178483.891),
fill = "tonexty",
mode = "lines",
name = "UAE Co2",
type = "scatter",
xsrc = "yusuf.sultan:60:78f0c2",
ysrc = "yusuf.sultan:60:6ec821"
)
trace2 <- list(
x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011),
y = c(584310.781, 588949.536, 593379.272, 603844.89, 608373.635, 622641.932, 618589.897, 593434.277, 608212.287, 649381.696, 668310.75, 682047.332, 671941.08, 690664.782, 648934.322, 634713.696, 638564.046, 643532.831, 649898.743, 681500.949, 616195.346, 597676.996, 585392.546, 581083.821, 575730.001, 609781.763, 616011.996, 619561.652, 618831.919, 636209.832, 607911.593, 623815.372, 614328.843, 611541.923, 619737.668, 608611.99, 592183.83, 568667.359, 613357.088, 609246.381, 654361.482, 647280.505, 611791.279, 645358.997, 652377.635, 658640.871, 665248.805, 667727.697, 680448.52, 635839.465, 659788.642, 626719.636),
fill = "tonexty",
mode = "lines",
name = "UK Co2",
type = "scatter",
xsrc = "yusuf.sultan:60:78f0c2",
ysrc = "yusuf.sultan:60:861744"
)
trace3 <- list(
x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011),
y = c(3475006.881, 3469455.043, 3580587.145, 3723075.764, 3864368.941, 4013564.503, 4180468.008, 4289143.22, 4439567.227, 4674130.549, 4997215.251, 5038817.366, 5236894.038, 5460859.73, 5247421.995, 5041043.235, 5251664.714, 5385825.576, 5540759.993, 5583297.193, 5339405.023, 5133477.304, 4892141.033, 4922962.168, 5050922.133, 5102337.14, 5111475.304, 5307934.829, 5511357.987, 5591291.253, 5431468.725, 5446199.064, 5525431.933, 5644473.754, 5718213.457, 5746621.706, 5852880.365, 5943902.639, 6024275.945, 6119676.617, 6356190.783, 6248685.344, 6260518.753, 6324581.243, 6415834.538, 6453802.656, 6369120.625, 6462651.127, 6302912.94, 5909971.888, 6068657.646, 5932289.25),
fill = "tonexty",
mode = "lines",
name = "USA Co2",
type = "scatter",
xsrc = "yusuf.sultan:60:78f0c2",
ysrc = "yusuf.sultan:60:3087af"
)
trace4 <- list(
x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011),
y = c(4255733.183, 4021521.893, 4020946.174, 4159771.46, 4301291.991, 4489537.436, 4703257.53, 4722377.268, 4908495.853, 5251367.687, 5768832.725, 5915450.386, 6168469.719, 6429402.438, 6235436.473, 6186650.705, 6447858.449, 6696136.351, 7002928.572, 7078157.077, 6806597.392, 6584978.58, 6472401.68, 6589991.369, 6865830.443, 7068890.568, 7180444.375, 7517643.36, 7880859.71, 7999831.858, 7892212.742, 8030737.334, 8221414.0, 8523167.763, 8776454.787, 9066906.856, 9315969.496, 9413412.687, 9348620.464, 9437732.231, 9761370.65, 9736251.7, 9954760.896, 10849758.252, 11704000.57, 12243819.64, 12783583.705, 13254455.841, 13338356.801, 13602182.783, 14325626.878, 14951807.465),
fill = "tonexty",
mode = "lines",
name = "China Co2",
type = "scatter",
xsrc = "yusuf.sultan:60:78f0c2",
ysrc = "yusuf.sultan:60:07fff6"
)
trace5 <- list(
x = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011),
y = c(4376315.144, 4151924.08, 4164413.882, 4313855.133, 4451939.685, 4655509.523, 4875023.477, 4894616.258, 5095831.882, 5442092.024, 5963975.797, 6121319.433, 6386318.855, 6653745.831, 6467429.228, 6438852.297, 6711644.094, 7011817.38, 7320963.815, 7410097.584, 7155178.745, 6959800.985, 6870821.23, 7022312.334, 7312940.419, 7559355.485, 7706306.843, 8079204.073, 8487157.823, 8662777.787, 8582789.516, 8768589.072, 9005048.233, 9337465.45, 9641386.41, 9986953.489, 10318193.599, 10457352.582, 10420532.235, 10582122.257, 10948033.852, 10940094.797, 11181552.079, 12131671.779, 13052525.152, 13654947.246, 14287948.453, 14865654.967, 15131431.793, 15568002.811, 16276577.221, 17026152.358),
fill = "tonexty",
mode = "lines",
name = "India Co2",
type = "scatter",
xsrc = "yusuf.sultan:60:78f0c2",
ysrc = "yusuf.sultan:60:f7748a"
)
data <- list(trace1, trace2, trace3, trace4, trace5)
layout <- list(
title = "Co2 emissions in kilotons, 1960-2011",
xaxis = list(title = "Year"),
yaxis = list(title = "Co2 Emissions (kt)")
)
p <- plot_ly()
p <- add_trace(p, x=trace1$x, y=trace1$y, fill=trace1$fill, mode=trace1$mode, name=trace1$name, type=trace1$type, xsrc=trace1$xsrc, ysrc=trace1$ysrc)
p <- add_trace(p, x=trace2$x, y=trace2$y, fill=trace2$fill, mode=trace2$mode, name=trace2$name, type=trace2$type, xsrc=trace2$xsrc, ysrc=trace2$ysrc)
p <- add_trace(p, x=trace3$x, y=trace3$y, fill=trace3$fill, mode=trace3$mode, name=trace3$name, type=trace3$type, xsrc=trace3$xsrc, ysrc=trace3$ysrc)
p <- add_trace(p, x=trace4$x, y=trace4$y, fill=trace4$fill, mode=trace4$mode, name=trace4$name, type=trace4$type, xsrc=trace4$xsrc, ysrc=trace4$ysrc)
p <- add_trace(p, x=trace5$x, y=trace5$y, fill=trace5$fill, mode=trace5$mode, name=trace5$name, type=trace5$type, xsrc=trace5$xsrc, ysrc=trace5$ysrc)
p <- layout(p, title=layout$title, xaxis=layout$xaxis, yaxis=layout$yaxis)
p
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.