I created a nice pie chart. Nothing too fancy.
Source <- plot_ly(Question1_2016, labels = Question1_2016$Source, values = Question1_2016$TotalExpense, type = 'pie')
in the area of my RMarkdown file, I can not seem to get the correct coding to get Source embedded in it.
My plot chunk looks like this:
```{r source, echo=FALSE}
Source
```
and when I go to knit it together I get this error
Error in eval(expr, envir, enclos) : object "Source" no found Calls: <Anonymous>...handle -> withCallingHandlers -> withVisible -> eval _. eval Execution Halted
Any idea?
Edited to add:
dput(Question1_2016[1:5, ])
structure(list(FY = c(2016, 2016, 2016, 2016, 2016), Source = c("All Other Sources",
"Business", "Federal", "Institutional Support", "Institutional Support-Cost Sharing"
), TotalExpense = c(1819424.18, 2850796.2, 47625255.58, 33363659.29,
6922360.06), Percent = c(1.5, 2.3, 39.2, 27.5, 5.7), Labels = c("All Other Sources 1.5 %",
"Business 2.3 %", "Federal 39.2 %", "Institutional Support 27.5 %",
"Institutional Support-Cost Sharing 5.7 %")), .Names = c("FY",
"Source", "TotalExpense", "Percent", "Labels"), row.names = c(11L,
22L, 33L, 44L, 55L), class = "data.frame")
Edited to Add my RMarkdown:
title: "UMD" author: "Laura Walker" date: "February 16, 2017"
output: html_document
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
R Markdown
Loading the Libraries
library(readxl)
library(reshape)
library(plotly)
library(tidyr)
Loading the Data Sets
ExpendData <- read_excel("C:/Users/user/Desktop/ExpendData.xlsx",
+ na = "empty")
SponsorData <- read_excel("C:/Users/user/Desktop/SponsorData.xlsx")
ProjectData <- read_excel("C:/Users/user/Desktop/ProjectData.xlsx")
Defining UltimateSponsor
In the cases where there is a Prime Sponsor, I've developed code to create an Ultimate Sponsor. When there is a Prime, the Ultimate Sponsor will take the identity of the Prime. When there is just a sponsor, the Ultimate Sponsor will take that identity.
ExpendData$UltimateSponsorID <- ifelse(ExpendData$Prime=="N", ExpendData$PrimeSponsorID, ExpendData$SponsorID)
Merging expend data with other tables
Merging expend data with sponsor data based on Ultimate Sponsor
ExpendData <-merge(x=ExpendData, y=SponsorData, by.x="UltimateSponsorID", by.y="SponsorID")
Merging expend data with project data based on project#
ExpendData <-merge(x=ExpendData, y=ProjectData, by.x="ProjectNumber", by.y="PROJECT")
Question 1
Question 1 asks "How much of your total expenditures for research and development R&D came from the following sources"
Question1 <-aggregate(TotalExpense~FY+Source, CurrentFY, sum)
Question1 <-Question1[order(Question1$FY),c(1:3)]
Extracting data for only FY 2016
Question1_2016 = subset(Question1, FY == "2016")
Constructing an FY16 Source of Funding Pie Chart
```
Question1_2016$Percent <- round(Question1_2016$TotalExpense/sum(Question1_2016$TotalExpense)*100, digits = 1)
Question1_2016$Labels <- paste(Question1_2016$Source, Question1_2016$Percent)
Question1_2016$Labels <- paste(Question1_2016$Labels, "%",sep = " ")
Source <- plot_ly(Question1_2016, labels = Question1_2016$Source, values = Question1_2016$TotalExpense, type = 'pie')
```
You can also embed plots, for example:
{r plot, echo=FALSE}
plot(Source)
Source
interactively, do you get an error? – eipi10