我能够创建一个桑基图。然而,当渲染时只有一半的情节出现在网络浏览器中:
关于如何在不过多使用 R 语言的情况下正确渲染情节的任何想法?
下面的代码复制了图表:
library(reshape2)
library(googleVis)
#Download the file at:
#https://ben.epe.gov.br/downloads/Matriz%20Energ%c3%a9tica%20Nacional%20ab2014.xlsx
#importing and formating the data
a <- read.xlsx('Matriz Energética Nacional ab2014.xlsx', sheetName = 'consolidada tep',
rowIndex = 24:49 , colIndex=2:10, header=FALSE) # startRow=4
b <- as.matrix(read.xlsx('Matriz Energética Nacional ab2014.xlsx', sheetName = 'consolidada tep',
rowIndex = 2:3, colIndex=2:10, header=FALSE, stringsAsFactors=FALSE) )
b <- paste0(b[1,],b[2,])
colnames(a) <- b
c <- read.xlsx('Matriz Energética Nacional ab2014.xlsx', sheetName = 'consolidada tep',
rowIndex = 24:49, colIndex=1:1, header=FALSE, stringsAsFactors=FALSE) # startRow=4
a <- cbind(c,a)
#converting to long format
a2 <- melt(a,id='X1')[,c(2,1,3)]
colnames(a2) <- c('source','target','value')
#googleVis
g <- gvisSankey(a2, from="source",
to="target", weight="value" ,
options=list(
height=500,
sankey="{link:{color:{fill:'lightblue'}}}"
))
cat(g$html$chart, file="tmp.html")
plot(g)