我正在尝试为 pokedex 制作一个闪亮的 R 应用程序,我做到了,所以当您从下拉列表中选择 pokemon 时,会出现其统计数据的条形图,然后我还尝试使用光栅 plotRGB 函数添加其图像,但 Shiny 只能显示一个图我尝试了多种方法将条形图和 plotRGB 结合起来,但它一直给我:“警告:gList 中的错误:“gList”中只允许使用“grobs””
这是我的 ui.R 代码:
shinyUI(
pageWithSidebar(
headerPanel("Shiny App Demo"),
sidebarPanel(
selectInput("Pokemon", "Please Select a Pokemon",
choices= pokemon_data$name)
),
mainPanel(plotOutput("dispPlot"))
)
)
这是我的 server.R 代码:
shinyServer(
function(input, output, session){
output$dispPlot <- renderPlot({
pokemon_name <- input$Pokemon
df <- melt(as.data.table(stats_df), id.vars = "name", variable.name = "Stats",
value.name="Num")
df<-df %>% arrange(df, name)
sub <- subset(df, name == pokemon_name)
stat_plot<- ggplot(sub, aes(x = Stats , y= Num, fill = Stats)) +
geom_bar(position="dodge", stat = "identity") + xlab(paste(sub$name,"Stats"))
number <- rownames(pokemon_data[pokemon_data$name == pokemon_name,])
path <- "C:/Users/wejda/Desktop/DS_Bootcamp/Week 6/Day 29/Data/Pokemon Images Dataset/pokemon_jpg/pokemon_jpg/"
ext <-".jpg"
full_path <- paste0(path, number,ext)
myJPG <- stack(full_path)
img_plot<-plotRGB(myJPG)
plot_list <- list(stat_plot,img_plot)
grid.arrange(grobs=plot_list,ncol=length(plot_list))
grid.newpage()
grid.draw(rbind(stat_plot, img_plot))
facet_wrap(img_plot,stat_plot)
})
}
)
有没有办法同时绘制条形图和图像图? This is what the pokemon image looks like This is what the bar plot looks like