Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot map获得正确的单击坐标_R_User Interface_Ggplot2_Click_Shiny - Fatal编程技术网

R 使用ggplot map获得正确的单击坐标

R 使用ggplot map获得正确的单击坐标,r,user-interface,ggplot2,click,shiny,R,User Interface,Ggplot2,Click,Shiny,我有一个闪亮的应用程序的开始,它有一个ggplot世界地图。我想获得点击绘图的坐标,这样用户就可以使用地图进行操作,但坐标非常奇怪(要么NULL要么非常小)。重复单击似乎只会更改一个坐标: ui.R: 服务器.R: library(shiny) library(maps) library(mapdata) library(ggplot2) library(rworldmap) shinyServer(function(input, output) { output$myworld &l

我有一个闪亮的应用程序的开始,它有一个ggplot世界地图。我想获得点击绘图的坐标,这样用户就可以使用地图进行操作,但坐标非常奇怪(要么
NULL
要么非常小)。重复单击似乎只会更改一个坐标:

ui.R:

服务器.R:

library(shiny)
library(maps)
library(mapdata)
library(ggplot2)
library(rworldmap)

shinyServer(function(input, output) {

  output$myworld <- renderPlot({

     world <- map_data("world")
     worldmap <- ggplot(aes(x = long, y = lat, group = group), data = world) +
       geom_path()

    print(worldmap)
  })

  output$clickcoord <- renderPrint({
          print(input$plotclick)
  })
})

只需在原始代码中将
print(worldmap)
替换为
worldmap
,您就可以得到您想要的。Shiny与ggplot2配合使用效果非常好。函数
print()
似乎会生成一个x和y在范围(0,1)内重置的图形

恕我直言,shiny不支持ggplot2(或更一般的网格图形)的打印位置。我尝试运行此代码,首次发现server.R文件中缺少右大括号和右括号。在添加这些之后,我现在看到
错误:参数“metaHandler”丢失,FireFox web选项卡中没有默认值。这些示例在我下面的闪亮教程中运行良好,因此我认为我没有缺少基本组件。对此表示抱歉。修复了缺少的分隔符。我仔细检查了这个例子,结果很好。你有最新的闪亮(0.8 iirc)吗?在一个例子中,我尝试了不同的设置,x-y坐标是0-1平方的,所以也许可以适当地缩放它们…@user1965813希望那里也有一些投影信息。
library(shiny)
library(maps)
library(mapdata)
library(ggplot2)
library(rworldmap)

shinyServer(function(input, output) {

  output$myworld <- renderPlot({

     world <- map_data("world")
     worldmap <- ggplot(aes(x = long, y = lat, group = group), data = world) +
       geom_path()

    print(worldmap)
  })

  output$clickcoord <- renderPrint({
          print(input$plotclick)
  })
})
library(shiny)
library(maps)
library(mapdata)

shinyServer(function(input, output) {

    output$myworld <- renderPlot({
      map("world2Hires")
    })

    output$clickcoord <- renderPrint({
      print(input$plotclick) 
    })

})