I am learning R and I love it so far. I am so impressed with one of the example provided in the "plotGoogleMaps" package. 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=”)
I Would like to apply the above example map to my below data. In my example sale = zinc (in above example). 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. 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 . See also the Wikipedia page of the World Geodetic System (used by GPS).
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)
# Set coordinates and reference system
coordinates(bubblechart) <- ~longt +latit
proj4string(bubblechart) <- CRS("+init=epsg:4326") # WGS 84
m <- bubbleGoogleMaps(bubblechart, zcol='sale', max.radius = 20000)
Change the max.radius
parameter to change bubble size. And change the key.entries
parameter to set different boundaries on the sales values.
You can also display your sales bubbles as a R plot with:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.