看板 Statistics 關於我們 聯絡資訊
[軟體程式類別]:R語言 [程式問題]:想在原有圖表中新增一項功能:當滑鼠移至圖表上時,可以自動顯示指定的標籤 [軟體熟悉度]:新手 [問題敘述]: 最近在練習r shiny時遇到了問題, 問題:想在原有圖表中新增一項功能,當滑鼠移至圖表上時,可以自動顯示指定的標籤內容 ============ [[更新]] 已將範例資料及完整程式碼放入以下雲端硬碟中 https://reurl.cc/GKKMkd ============ 我的程式碼沒有顯示error, 但是圖表卻沒有正常顯示出來,程式碼如下: server <- function(input,output){ filtered_data <- reactive({ test[test$var1 %in% input$select1 &test$var2 %in% input$select2 & test$var3 %in% input$select3 &test$dis_cate %in% input$select4, ] }) output$distPlot <- renderPlotly({ gg <- ggplot(filtered_data(), aes(x = year, y = money/1000000, fill = dis_cate)) + labs(x = "年度", y = "百萬元", title = "直條圖") + geom_text(aes(label = round(money/1000000, digits = 2)), vjust = -0.5, size = 4, position = position_dodge(width = 0.9)) + geom_bar(stat = "identity", position = position_dodge(), alpha = 2/5) + scale_x_continuous(breaks = unique(filtered_data()$year), labels = unique(filtered_data()$year)) gplotly(gg) }) output$summoneyOut <- renderText({ sum_ <-round(sum(filtered_data()[["money"]])/100000000,digits = 2) paste0("2000-2020年共花費",sum_,"億元") }) } shinyApp(ui = ui, server = server) ---------------------- 原本沒有新增這個功能前的程式碼: (這邊的程式碼是可以正常顯示圖表的,也就是可以正常運作) ---------------------- output$distPlot <- renderPlot({ ggplot(filtered_data(),aes(x=year,y=money/1000000,fill=dis_cate))+ labs(x="年度",y="百萬元",title=element_text("直條圖"))+ geom_text(aes(label = round(money/1000000,digits = 2)), vjust = -0.5, size =4,position = position_dodge(width = 0.9))+ geom_bar(stat = "identity", position = position_dodge(),alpha=2/5)+ scale_x_continuous(breaks = unique(filtered_data()$year), labels = unique(filter }) 試了好久找不到問題在哪裡….. 先謝謝大家了~~ ----- Sent from JPTT on my Google Pixel 6. -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.219.175.56 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Statistics/M.1696564032.A.D22.html
locka: 請附上測試資料~~感謝~~10/06 12:50
已更新 ※ 編輯: linda841004 (61.219.175.56 臺灣), 10/06/2023 14:09:27 雖然過了有點久,但我把自問自答放在雲端裡面,或許可以提供給有類似問題的人(?) ※ 編輯: linda841004 (27.247.4.22 臺灣), 11/24/2023 14:49:36