简体   繁体   English

将点(纬度和经度)绘制到ggmap中

[英]Plot points (latitude & Longitude) into a ggmap

I'm trying to make a shiny app and a part of it, is a map that should print the latitude and longitude points into a map. 我正在尝试制作一个闪亮的应用程序及其中的一部分,是一张应该将纬度和经度点打印到地图中的地图。 I've been trying to do it, but I get an error telling me that it cannot find my object d . 我一直在尝试这样做,但是我收到一个错误,告诉我它无法找到我的对象d

If I just put the map works good, without points but it's a step. 如果我只是把地图运作良好,没有点,但这是一步。

My server.R code is: 我的server.R代码是:

#Reactive Map
  output$MapPr <- renderPlot({
    d <- switch(input$chDatabase,
                "BPD 2013 Baltimore" = read.csv("./Data/BPD_13_Bal.csv", 
                                                header=TRUE, sep=",", dec="."),
                "BPD 2014 Baltimore" = read.csv("./Data/BPD_14_Bal.csv", 
                                                header=TRUE, sep=",", dec=".")
    )
    library(ggmap)
    map <- get_map(location = 'Baltimore', zoom = 12)
    ggmap(map)
    ggmap(map) +
      geom_point(aes(as.numeric(d$Longitude), as.numeric(d$Latitude)), data = d, alpha =.5, color = "darkred")
  }, width = 800, height = 700)

At the ui.R I've got: 在ui.R我有:

################################
#2nd tabpanel for Reactive Map
tabPanel("Reactive Map", 

  #SideBarLayout for sidebar Panel for the options of the map       
  sidebarLayout(

    #SideBar Panel with options to adjust the map
    sidebarPanel(

      #Databases selection
      selectInput("chDatabaseMap","Choose DataBase:", 
          choices = c("BPD 2013 Baltimore", "BPD 2014 Baltimore"))
    ),
    ###################################       
    #Main panel to put plots  
    mainPanel(
      plotOutput("MapPr")
    )
  )
)

By the way, I've seen that is problem with the load of the csv file, or at least I think that, but the previous plots (histograms, pies, box plots, etc) I've been doing with the same system, they work. 顺便说一句,我已经看到csv文件的负载存在问题,或者至少我认为,但是我以前使用相同系统进行的绘图(直方图,馅饼,箱形图等),他们工作。

I don't know how should I continue this. 我不知道该怎么办呢。

The columns of latitude and longitude are both numeric. 纬度和经度的列都是数字的。

Does changing the server.R to the below work? 是否将server.R更改为以下工作?

library(ggmap)

d <- reactive({
    switch(input$chDatabase,
           "BPD 2013 Baltimore" = read.csv("./Data/BPD_13_Bal.csv", 
                                           header=TRUE, sep=",", dec="."),
           "BPD 2014 Baltimore" = read.csv("./Data/BPD_14_Bal.csv", 
                                           header=TRUE, sep=",", dec="."))
})



output$MapPr <- renderPlot({
    df <- d()
    map <- get_map(location = 'Baltimore', zoom = 12)
    ggmap(map) +
        geom_point(aes(as.numeric(Longitude), 
                       as.numeric(Latitude)), 
                   data = df, alpha =.5, color = "darkred")
}, width = 800, height = 700)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM