楼主: oliyiyi
2146 2

R-Markdown and Knitr Tutorial (Part 1) [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
66105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

楼主
oliyiyi 发表于 2016-6-18 18:21:40 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
By Riddhiman








(This article was first published on Modern Data » R, and kindly contributed to R-bloggers)

R-Markdown is a great way to create dynamic documents with embedded chunks of R code. The document is self contained and fully reproducible which makes it very easy to share. This post will be the first in a multi part series on how to embed Plotly graphs in R-Markdown documents as well as presentations.
R-Markdown is a flavor of markdown which allows R-users to embed R code into a markdown document. The document is then ‘knit’ using knitr to create a HTML file.
Getting started# Not run# install.packages('rmarkdown')# install.packages('plotly')
  • Note: you can download the function definition forGetYahooData() here
  • Now we should be good to go…

Creating a R-Markdown document
  • Click on File -> New File -> R Markdown as shown below.
  • You should now see a dialog as shown below. Select ‘Document’ in the left panel and fill in title and author field and hit ‘OK’.


  • You should now have a document which looks like this –


Code chunksTo embed R code into the document, code needs to be inserted as shown below.


Inserting a Plotly graphInserting an awesome interactive Plotly chart is as simple as printing out the plotly object in a code chunk. Use the code snippet below.
source("Yahoo Stock Data Pull.R")AAPL <-  GetYahooData("AAPL")IBM <- GetYahooData("IBM")# Plotly chart library(plotly)mat <-  data.frame(Date = AAPL$Date,                    AAPL = round(AAPL$Adj.Close,2),                   IBM = round(IBM$Adj.Close,2))p <- mat %>%   plot_ly(x = Date, y = AAPL, fill = "tozeroy", name = "Microsoft") %>%   add_trace(y = IBM, fill = "tonexty", name = "IBM") %>%   layout(title = "Stock Prices",          xaxis = list(title = "Time"),         yaxis = list(title = "Stock Prices"))p  # Thats it !
Knitting the R-Markdown documentNow that our R-Markdown document is complete with text, code and graphs, we can go ahead and click the little ‘Knit HTML’ button to generate a HTML file.

We now have a nicely formatted HTML file !



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Tutorial tutor Down PART Mark documents published article dynamic create

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

沙发
tianwk 发表于 2019-7-26 00:04:58
thanks for sharing
已有 1 人评分论坛币 收起 理由
oliyiyi + 5 精彩帖子

总评分: 论坛币 + 5   查看全部评分

藤椅
piiroja 发表于 2020-4-16 00:24:05
thx for sharing~

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-1 03:19