简体   繁体   English

PlotGoogleMaps-需要BubbleGoogleMaps中的帮助

[英]PlotGoogleMaps -Need help in bubbleGoogleMaps

I am learning R and I love it so far. 我正在学习R,到目前为止我喜欢它。 I am so impressed with one of the example provided in the "plotGoogleMaps" package. “ plotGoogleMaps”包中提供的示例之一给我留下了深刻的印象。 Is it possible to apply that my below example? 是否可以应用下面的示例? please help. 请帮忙。

The example I see in the package 我在包中看到的示例

    # Data preparation
    library(plotGoogleMaps)
    data(meuse)
    coordinates(meuse)<-~x+y
    proj4string(meuse) <- CRS('+init=epsg:28992')

    m<-bubbleGoogleMaps(meuse,zcol='zinc')

    m<-bubbleGoogleMaps(meuse,zcol='cadmium',layerName='Bubble plot - meuse',
                        colPalette=terrain.colors(5),strokeColor=&rdquo;)

I Would like to apply the above example map to my below data. 我想将以上示例地图应用于我的以下数据。 In my example sale = zinc (in above example). 在我的示例中,sale =锌(在上述示例中)。 And I want to display my other attributes while I am highlighting my bubble. 我想在突出显示气泡时显示其他属性。

  library(plotGoogleMaps)
    bubblechart = read.table(text="Itemcode,sale,name,longt,latit
                        101,1112,A,-89.6171,35.24992
                   105,1540,B,-90.0154,35.10510
                   106,2200,C,-89.5213,34.93277
                   111,1599,D,-86.8642,36.34807
                   113,4500,E,-86.6125,36.19958
                   114,3569,F,-90.4611,30.02196",
                   header=TRUE,sep=",")

Please help... 请帮忙...

bubbleGoogleMaps() requires you to transform your bubblechart data in a SpatialPointsDataFrame. bubbleGoogleMaps()要求您在bubblechart中转换bubblechart数据。 For this you need to specify the coordinates and the reference system in which Longitude and Latitude were measured. 为此,您需要指定测量经度和纬度的坐标和参考系统。 There is a related GIS stackexchange question: Converting geographic coordinate system in R . 有一个相关的GIS stackexchange问​​题: 在R中转换地理坐标系 See also the Wikipedia page of the World Geodetic System (used by GPS). 另请参见世界大地测量系统 (由GPS使用)的Wikipedia页面。

Inspect an existing SpatialPointsDataFrame 检查现有的SpatialPointsDataFrame

library(plotGoogleMaps)
data(meuse)
# meuse is a data frame
class(meuse)
# Specify coordinates and projection system
coordinates(meuse)<-~x+y
proj4string(meuse) <- CRS('+init=epsg:28992')
# meuse has become a "SpatialPointsDataFrame"
class(meuse)
# Which contains several objects
class(meuse@data)
class(meuse@coords)
summary(meuse@coords)
class(meuse@bbox)
class(meuse@proj4string)
help(SpatialPointsDataFrame)
# Convert meuse back to a data frame 
meusedtf <- as.data.frame(meuse)

Create your own SpatialPointsDataFrame 创建自己的SpatialPointsDataFrame

# Set coordinates and reference system
coordinates(bubblechart) <- ~longt +latit
proj4string(bubblechart) <- CRS("+init=epsg:4326") # WGS 84

Generate maps 产生地图

m <- bubbleGoogleMaps(bubblechart, zcol='sale', max.radius = 20000)

在此处输入图片说明

Change the max.radius parameter to change bubble size. 更改max.radius参数以更改气泡大小。 And change the key.entries parameter to set different boundaries on the sales values. 并更改key.entries参数以在销售值上设置不同的边界。

You can also display your sales bubbles as a R plot with: 您还可以使用以下方式将您的销售泡泡显示为R图:

plot(bubblechart)
points(bubblechart@coords, pch=21, cex=(bubblechart$sale)/1000, col="black", bg="blue")
bubble(bubblechart, "sale", maxsize = 2.5, main = "Sales in the US", key.entries = 2^(-1:4))

These R plots would look nicer if you add a map of the US states in the background to help identify the areas. 如果您在背景中添加美国各州的地图以帮助识别区域,则这些R图看起来会更好。

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

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