R-如何在弹出窗口中粘贴同一变量的多列(传单) [英] R- how to paste multiple column of same variable in popup (leaflet)

查看:69
本文介绍了R-如何在弹出窗口中粘贴同一变量的多列(传单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含4行和几列的数据集,分别是国家/地区,位置,匹配次数,纬度,经度. 可重现的是:

I have a dataset of 4 rows and a few columns which are country, location, hits, lat, lon. Reproducible is:

structure(list(country = c("France", "France", "France", "France")
, location("Ile-de-France, Paris", "Ile-de-France, Villebon-sur-yvette", "Nord-Pas-de-Calais, Hérin", "Nord-Pas-de-Calais, Lille")
, Hits(1, 1, 3, 5)
, lat = c(46.227638, 46.227638, 46.227638, 46.227638)
, Ion = c(-2.213749, 2.213749, 2.213749, 2.213749)
)
, .Names = c("country", "location", "Hits", "lat", "Ion")
, class = "data.frame")

我想在弹出窗口中使用它,并将所有位置和命中显示为4条单独的行.

I want to use this in popup and show all the location and hits as 4 seperate lines.

我正在使用的当前代码是:

current code i am using is:

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addCircles(lng=area$longitude, lat=area$latitude, popup=paste("Country:", area$Country, "<br>"
                                                            , "Location:", area$Location, "-", area$Hits, "<br>"))

如果您有任何疑问,请随时提问.

If u have questions feel free to ask.

推荐答案

您的示例中有一些错误. 试试这个

There were some mistakes in your example. Try this

library(leaflet)
area <- data.frame(country = c("France", "France", "France", "France")
           , location= c("Ile-de-France, Paris", "Ile-de-France, Villebon-sur-yvette", "Nord-Pas-de-Calais, Hérin", "Nord-Pas-de-Calais, Lille")
           , Hits= c(1, 1, 3, 5)
           , lat = c(46.234638, 46.456638, 46.288638, 46.900638)
           , lon = c(2.313749, 2.413749, 2.513749, 2.613749)
)


m <- leaflet() %>%
addTiles() %>%  # Add default OpenStreetMap map tiles
addCircles(lng=area$lon, lat=area$lat, 
popup=paste("Country:", area$country, "<br>", "Location:", area$location, "-", area$Hits, "<br>"))

您的示例的主要问题是在提供的坐标中.您为四个点分配了相同的坐标.这样只会显示最后一点.

The main issue with your example is in the provided coordinates. You assigned the same coordinates to the four points. This results in the display of the last point only.

这篇关于R-如何在弹出窗口中粘贴同一变量的多列(传单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆