【发布时间】:2016-03-13 23:37:14
【问题描述】:
我正在尝试绘制一张热图,以可视化多个社交媒体平台上的不同参与度衡量标准。我已经按照建议的解决方法来处理闪亮和 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 文件
服务器.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)
我不知道还能做什么。想法?
【问题讨论】: