我试图开发一个简单的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