我有一个闪亮的代码可绘制wordcloud。我需要在条形图或直方图中绘制常用词。
我在server.r和ui.r之间分配了代码。文件。云完美运行。现在,我需要在其旁边放置一个条形图。
我可以使用GGPLOT通过RStudio进行此操作,但是我无法通过Shiny进行绘制
请如何在下面的代码中执行此操作。
server.r
shinyServer(function(input, output) {
filtered_data <- reactive ({
data <- tesesFO
data <- subset(
data,
Ano >= input$ano[1] & Ano <= input$ano[2]
)
# Trata a Caixa
if (input$depto != "Todos"){
data <- subset(
data,
Depto ==input$depto
)
}
data
})
getTermMatrix <- memoise(function(book) {
data <- tesesFO
data <- subset(
data,
Ano >= input$ano[1] & Ano <= input$ano[2]
)
# Trata a Caixa
if (input$depto != "Todos"){
data <- subset(
data,
Depto == input$depto
)
}
data
data <- data$ResumoBR
# Separando somente os resumos
resumosBR <- data
#text <- readLines(sprintf("./%s.txt.gz", book),
# encoding="UTF-8")
myCorpus = Corpus(VectorSource(resumosBR))
myCorpus = tm_map(myCorpus, content_transformer(tolower))
myCorpus = tm_map(myCorpus, removePunctuation)
myCorpus = tm_map(myCorpus, removeNumbers)
myCorpus = tm_map(myCorpus, removeWords,
c(stopwords("SMART"), "a","a","à"))
myDTM = TermDocumentMatrix(myCorpus,
control = list(minWordLength = 1))
m = as.matrix(myDTM)
v1 <- sort(rowSums(m), decreasing = TRUE)
d <- data.frame(word = names(v1), freq = v1)
})
wordcloud_rep <- repeatable(wordcloud)
output$plot <- renderPlot({
terms <- reactive({
# Change when the "update" button is pressed...
input$update
data <- tesesFO
data <- subset(
data,
Ano >= input$ano[1] & Ano <= input$ano[2]
)
# Trata a Caixa
if (input$depto != "Todos"){
data <- subset(
data,
Depto %in% input$depto
)
}
data
# ...but not for anything else
isolate({
withProgress({
setProgress(message = "Processing corpus...")
getTermMatrix(data)
})
})
})
v <- terms()
wordcloud_rep(names(v), v, scale=c(4,0.5),
min.freq = 1, max.words=input$max,
colors=brewer.pal(8, "Dark2"))
})
})
ui.R
tesesFO <<- read.csv("TesesFOResumoUnico.csv", colClasses = "character",stringsAsFactors = TRUE, sep = ";")
##
# CSV Sample
#Sysno;Autor;Título;Ano;Depto;Area;Assuntos;Orientador;ResumoBR
#709035;Sampaio, Maria Carmeli Correia;Aspectos clinicos da mucosa bucal de pacientes com carcinoma epidermoide da boca, sua correlacao com a microbiota fungica e sorotipos de candida albicans antes e durante a radioterapia;1986;ESTOMATOLOGIA;Semiologia;MUCOSA ORAL;Birman, Esther Goldenberg;
##
shinyUI(
fluidPage
(
mainPanel(
tabPanel("Nuvem FOUSP",
br(),
sliderInput("max", "Número máximo de palavras:",
min = 1, max = 300, value = 20),
plotOutput("plot",width = "100%",height=700)
)
)
)
)