我正在尝试基于已加载的csv创建散点图,但是当我运行代码时,当我包含aes映射时却没有显示任何图或出现错误:“应使用//more than 2 chars on start uri segment
$route['^(\w{3,})\/?(:any)'] = '$1/$2';
//2 chars lang + /uri_segment
$route['^(\w{2})\/?(:any)'] = '$2';
//only 2 chars
$route['^(\w{2})$'] = $route['default_controller'];
创建映射或//more than 2 chars on start uri segment
$route['^([a-zA-Z]{3,})/(:any)'] = '$1/$2';
//2 chars lang + /uri_segment
$route['^([a-zA-Z]{2})/(:any)'] = '$2';
//only 2 chars
$route['^([a-zA-Z]{2})'] = $route['default_controller'];
。”
任何人都可以向我指出我要去哪里哪里吗?
代码:
aes()
答案 0 :(得分:0)
如错误消息所述,您使用的是aes
错误。该函数采用列名,而不是变量引用。也就是说,替换
aes(x = output$x, y = output$y)
作者
aes(x = x, y = y)
或者,您更有可能希望能够通过输入来控制绘图,因此您想使用
aes_string(x = input$x, y = input$y)
您的代码中也有很多流浪括号和花括号。删除那些。此外,mainPanel
是您需要调用的函数。您的代码而是为其分配了一些内容。
最后,您实际上需要 plot 。解决所有这些问题后,相关代码如下:
ui <- fluidPage(
titlePanel("Pig Breeds"),
sidebarLayout(
sidebarPanel(…),
mainPanel(
plotOutput(outputId = "scatterplot")
)
)
)
server <- function(input, output) {
output$scatterplot <- renderPlot({
p = ggplot(data = read.csv("eu_pigs.csv")) +
aes_string(x = input$x, y = input$y) +
geom_point()
plot(p)
observeEvent(input$update, print(as.numeric(input$update)))
})
}
如果图对象是您在renderPlot
函数中执行的最后一件事,则可以省略plot
:
output$scatterplot <- renderPlot({
ggplot(data = read.csv("eu_pigs.csv")) +
aes_string(x = input$x, y = input$y) +
geom_point()
})