【问题标题】:Plotting issue with HeatMap in R shiny在 R Shiny 中绘制 HeatMap 的问题
【发布时间】:2019-11-17 07:47:46
【问题描述】:

我想在 rshiny 应用程序中绘制热图。我设法让它在 r 笔记本上工作,结果正确。但是,当我将相同的代码放入我的 rshiny 应用程序时,热图结果却有所不同。

Here is the code in my r shiny notebook

这是插入到 rshiny 应用程序中的相同代码:

output$heatmapPlot <- renderPlotly({

heat_map_data <- data %>% 
   group_by(year,town,estate_type,flat_type,storey_range) %>% 
  summarise(median_sales = median(resale_price ))

df_matrix <- data.frame(heat_map_data)
print(df_matrix)

ggplot(df_matrix, aes(x = flat_type, y = storey_range, fill = median_sales)) + 
  geom_tile() +
  scale_y_discrete(limits = rev(levels(as.factor(df_matrix$storey_range))))              
})

rshinyapp 中的结果:Result in rshiny

有人可以帮我解决这个问题吗?谢谢!

【问题讨论】:

  • 请查看ggplotly,这是一个将ggplot2::ggplot() 对象转换为绘图对象的函数。

标签: r shiny heatmap


【解决方案1】:

由于您使用了renderPlotly(),请将ggplot() 对象分配给ggplotly()

p<- ggplot(....)

p1<- ggplotly(p)

p1

ggplot() 函数之前比较 print() 函数的结果。将您的数据集包含在反应函数中并相应地使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-30
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    相关资源
    最近更新 更多