R中的Streamgraph包将运行数据,但不会显示图表

时间:2016-11-17 19:36:41

标签: r rstudio stream-graph

我一直在这里和其他地方环顾四周,但我还没有弄清楚为什么我的图表不会显示出来。 r中的streamgraph函数将运行而不会出现错误,但查看器窗格中不会显示任何内容 这是我解决这个问题的所有代码。

library(psych)
library(corrplot)
library(ggplot2)

#Load Data Set
movie1 = read.csv(file.choose(), header=TRUE)

#installing and loading streamgraph
install.packages("devtools")
library(devtools)
install.packages("zoo")
devtools::install_github("hrbrmstr/streamgraph")
library(streamgraph)

#Creating a data set with the addition of year
names(movie1)
movie2 = movie1[,c(5, 10, 19, 22, 24, 26, 28, 8, 9)]
#Cleaning Data Set
is.na(movie2) = !movie2
movie2 = na.omit(movie2)
#Checking Data
str(movie1)
names(movie2)
str(movie2)
#Creatubg new data set with only desired variables
m2 = movie2[,c(7, 5, 6)]
#sorting data set 
m3 <- m2[order(m2$movie_facebook_likes),]
str(m3)
summary(m3)
head(m3)
View(m3)

#Changing the data type
#year to a numeric
m3$yearc <- as.numeric(m3$title_year)
#year to a date
m3$year <- as.Date.factor(m3$title_year, format = "%Y")
str(m3$year)
#Movie facebook likes to numeric
m3$MFBL <- as.numeric(m3$movie_facebook_likes)
#grouping Movie Facebook Likes into Quantiles
m3$MFBLg <- with(m3, cut(m3$MFBL, quantile(m3$MFBL, probs = seq(0, 1, 0.25)), labels = c("Very Low", "Low", "High", "Very High")))
str(m3$MFBLg)
summary(m3$MFBLg)
m3 = na.omit(m3)
#Movie Facebook Likes as a Character
m3$MFBLC <- as.character(m3$MFBLg)
str(m3$MFBLC)
View(m3$MFBLC)

#Creating Variables to load into StreamGraph
value <- m3$imdb_score
key <- m3$MFBLC
date <- m3$year
#Creating data frame for StreamGraph
str(key)
df <- data.frame(key, value, date, stringsAsFactors = FALSE)
str(df)
head(df)

#This is the most basic way to input
streamgraph(df,key, value, date) 
#This way outputs the graph as a html file
dir.create("C:\\newfolder")
saveWidget(streamgraph(df, key, value, date), file = "C:\\newfolder\\sg.html")

#This was allows for easier graphical manipulation
df %>%
  streamgraph(key, value, date, interactive = TRUE) %>%
  sg_axis_x(tick_interval = 20, tick_units = "year", tick_format = "%m%d%Y") %>%
  sg_axis_y( tick_count = 10)

#This is a test to compare and see why my data won't create a graph
data <- read.csv("http://bl.ocks.org/WillTurman/raw/4631136/data.csv", stringsAsFactors=FALSE)
data$date <- as.Date(data$date, format="%m/%d/%y")
str(data)

streamgraph(data, interactive=TRUE) %>% sg_colors("Reds")

0 个答案:

没有答案