简体   繁体   English

在 R shiny 中绘制热图问题

[英]Plotting issue with HeatMap in R shiny

i want to plot a heatmap in rshiny app.我想 plot rshiny 应用程序中的热图。 I managed to get it work on r notebook with the correct result.我设法让它在 r 笔记本上工作,结果正确。 However, when i put the same code into my rshiny app, the heatmap result was different.但是,当我将相同的代码放入我的 rshiny 应用程序时,热图结果是不同的。

Here is the code in my r shiny notebook这是我的 r shiny 笔记本中的代码

Here is the same code inserted in rshiny app:这是插入 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))))              
})

The result in rshinyapp: Result in rshiny rshinyapp 中的结果: rshiny 中的结果

Can someone pls help me with this.有人可以帮我解决这个问题。 Thank you!谢谢!

Please assign ggplot() object to ggplotly() since you have used renderPlotly() .由于您使用了 renderPlotly() ,请将ggplot() object 分配给ggplotly() renderPlotly()

p<- ggplot(....)

p1<- ggplotly(p)

p1

Compare the result of print() function before the ggplot() function.ggplot() ) function 之前比较 print() function 的结果。 Contain your data set into reactive function and use it accordingly.将您的数据集包含在反应式 function 中并相应地使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM