シェイプファイルを使用して作成された 'Total Population'と 'Population Density'の2つのマッププロットがあります。さて、私は合計人口から人口密度に変更することができるように、光沢のあるアプリを構築しようとしているので、プロットはそれに応じて変更する必要があります。Shinyアプリケーションを作成しようとするとエラーが発生する
警告:でエラーが発生しました:ggplot2クラス行列のデータと
を対処する方法を知りませんが、ここで私がしようとしてきたコードだ私は、コードを実行したとき、私は、次のエラーコードを得ました使用:
library(shiny)
library(ggplot2) #Loading necessary libraries
ui <- fluidPage(
selectInput("mr",
label="Type of Plot",
choices=c("Total Population", "Density"),
selected="Total Population"),
plotOutput("curv") #Giving an input name and listing out types to choose in the Shiny app
)
server <- function(input, output){
output$curv <- renderPlot({
ggplot() +
geom_polygon(data = final.plot==input$mr,
aes(x = long, y = lat, group = group, fill = Population),
color = "black", size = 0.20) +
coord_map()+
scale_fill_distiller(name="Population", palette = "YlGn")+
labs(title="Population in Australia")
}) # Output with the data file and input string to change when input changes.
}
shinyApp(ui = ui, server = server)
ご協力いただきありがとうございます。
UPDATE:
私のデータセットは、次のようになります。これは、 "final.plot" と呼ばれるデータフレームに格納されて
id long lat order hole piece
1 Ashmore and Cartier Islands 123.1169 -12.25333 1 FALSE 1
2 Ashmore and Cartier Islands 123.1206 -12.25611 2 FALSE 1
3 Ashmore and Cartier Islands 123.1222 -12.25861 3 FALSE 1
4 Ashmore and Cartier Islands 123.1239 -12.25528 4 FALSE 1
5 Ashmore and Cartier Islands 123.1258 -12.25333 5 FALSE 1
6 Ashmore and Cartier Islands 123.1275 -12.25619 6 FALSE 1
group Population Density
1 Ashmore and Cartier Islands.1 NA NA
2 Ashmore and Cartier Islands.1 NA NA
3 Ashmore and Cartier Islands.1 NA NA
4 Ashmore and Cartier Islands.1 NA NA
5 Ashmore and Cartier Islands.1 NA NA
6 Ashmore and Cartier Islands.1 NA NA
。他の州の人口と密度の値があります。私は、人口の静的なビジュアライゼーションを作成することができましたし、それは次のようになります。
あり密度のための同様のものだと私はので、これら二つの間で切り替えることができシャイニーアプリを作成しようとしていますそれに応じてプロットも変わります今、私は次のコードを試してみた:
library(shiny)
library(ggplot2) #Loading necessary libraries
ui <- fluidPage(
selectInput("pop",
label="Type of Plot",
choices=c("Population", "Density"),
selected="Total Population"),
plotOutput("curv") #Giving an input name and listing out types to choose in the Shiny app
)
server <- function(input, output){
output$curv <- renderPlot({
ggplot() +
geom_polygon(data = final.plot,
aes(x = long, y = lat, group = group, fill = input$pop),
color = "black", size = 0.25) +
coord_map()+
scale_fill_distiller(name="Density", palette = "Spectral")+
labs(title="Population in Australia")
})
}
shinyApp(ui = ui, server = server)
をしかし、私は、「連続尺度に供給された離散値を」というエラーを取得しています。
UPDATE 2:ここで私が使用しているデータセットへのリンクです :私はあなたのコードを簡単に見ていたとの提案がいくつかありました Dataset
まず、反応性のあるデータセットを作成して(入力$ mrに応じて)、ggplotに渡すことができます。 –
この 'data = final.plot == input $ mr 'はうまく動作しない可能性があります。これはエラーメッセージを説明しています。私は他の問題(例えば、 'final.plot'とは何か、' mr'は何をするのか)を疑っていますが、あなたの例が[再現可能]でないと助けがありません(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610)。 –
こんにちは、私は投稿を編集しました。あなたのことを見てコメントすることができたのは素晴らしいことでしょう。ありがとう! –