我試圖開發一個簡單的Shiny APP來顯示條形圖。在下面的示例中(https://shiny.rstudio.com/gallery/telephones-by-region.html),情節是按地區電話。我想簡單一點:只需要一個候選人(我的數據:dados)。R ggplot發生錯誤
主要問題是使用條形碼內部的input
命令。原來
barplot(WorldPhones[,input$region]*1000,
main=input$region,
ylab="Number of Telephones",
xlab="Year")
應
ggplot(data=dados, aes(x=dados[input$candidato])) +
geom_bar(stat="count")
這樣做可以取代,我得到了錯誤:
Don't know how to automatically pick scale for object of type tbl_df/tbl/data.frame. Defaulting to continuous. Warning: Error in : Discrete value supplied to continuous scale
數據樣本:
Candidato1 Candidato2 Candidato3
<chr> <chr> <chr>
POSITIVO NEGATIVO POSITIVO POSITIVO
NEGATIVO POSITIVO NEGATIVO NEGATIVO
POSITIVO POSITIVO NEGATIVO NEGATIVO
我該如何解決這個問題?似乎ggplot不能接受我的字符串,但外面閃亮,工作正常。
Tks,Ricardo。
你應該解釋從'input $ candidato'來自哪裏?你想用它做什麼?列中是列名還是列值?如果'input $ candidato'表示列中的過濾器值,那麼列名稱是什麼? –
你可能想要'ggplot(data = dados,aes_string(x = input $ candidato))+ geom_bar(stat =「count」)''。不要在'aes'中使用'$'。 – Axeman