我正在尝试绘制一个热图,以便在几个社交媒体平台上可视化不同的参与度量。我已经按照建议的解决方法来处理闪亮和ggplot2之间的几个问题,但是最后一个问题仍然存在:
我的ui.R文件
# ui.R
library(shiny)
# Define UI for application that draws a heat map
shinyUI(fluidPage(
# Application title
titlePanel("Social Media"),
# select platform and measure
sidebarLayout(
sidebarPanel(
selectInput("medium", "Choose a platform:",
choices = c("twitter", "facebook", "linkedin")),
selectInput("measure", "Choose a measure:",
choices = c("audience", "reach", "kudos", "engagement", "clicks"))
),
# plot heat of measure
mainPanel(
plotOutput('heat'))
)
))
我的server.R文件
library(shiny)
library(ggplot2)
library(dplyr)
library(readr)
social_media <- read_csv("data/social_media.csv")
# Define server logic required to draw a heat map
shinyServer(function(input, output) {
output$heat <- renderPlot({
plot_data <- reactive({
social_media %>%
filter(social_media$source==input$medium)
})
ggplot(plot_data(), aes_string(x="hour_of_day", y="day"),
environment = environment()) +
geom_raster(aes_string(fill="input$measure"))
})
})
而不是我期望的热图,我得到一个单色图,其中填充看起来是作为因子绘制的度量: http://i.imgur.com/tA6kX7d.png)http://i.imgur.com/8RLU453.png
我的数据集中的变量名对应于选择输入: 来源:本地数据框[6 x 20]
time date
(chr) (time)
1 03:55 PM 2014-01-02
2 03:30 PM 2014-01-03
3 04:30 PM 2014-01-06
4 06:04 PM 2014-01-07
5 11:53 AM 2014-01-08
6 04:15 PM 2014-01-08
Variables not shown: message text (chr), audience (int), reach (int), kudos (int), engagement (int), author (chr),
account name (chr), message URL (chr), clicks (int), tags (chr), source (chr), datetime (chr), date_time (time),
hour_of_day (int), day (fctr), week (dbl), month (fctr), year (dbl)
我不知道还能做什么。想法?
答案 0 :(得分:0)
将fill="input$measure"
更改为fill=input$measure
。该变量已经是一个字符串。您的代码目前正在考虑将填充数据作为单个字符串(或因素导致其ggplot),&#34;输入$ measure&#34;。