Search code examples
rggplot2ggmap

Plotting sized circles using R


have visualised the following set of data in Tableau but need to know how to do it using R as I'm new to it. enter image description here

Dataset:

    Merchandise Stores Year Total.Sales Latitude Longitude

1   White goods Shop01 2015  45,547,000 -37.8594  144.7994
2   White goods Shop02 2015  28,775,000 -37.8532  147.5463
3   White goods Shop03 2015  17,029,000 -38.3697  142.4617
4   White goods Shop04 2015  28,827,000 -34.3698  150.6471
5   White goods Shop05 2015  38,929,000 -33.4187  149.5702
6   White goods Shop06 2015  10,740,000 -31.0025  150.1511
7   White goods Shop07 2015  15,008,000 -28.8214  153.2600
8   White goods Shop08 2015  10,013,000 -42.8826  147.3216
9   White goods Shop09 2015  14,556,000 -27.4050  152.4424
10  White goods Shop10 2015  10,669,000 -28.0632  148.2859
11    Groceries Shop01 2015  14,334,000 -37.8594  144.7994
12    Groceries Shop02 2015   6,521,000 -37.8532  147.5463
13    Groceries Shop03 2015  30,025,000 -38.3697  142.4617
14    Groceries Shop04 2015   5,899,000 -34.3698  150.6471
15    Groceries Shop05 2015   5,333,919 -33.4187  149.5702
16    Groceries Shop06 2015   1,915,000 -31.0025  150.1511
17    Groceries Shop07 2015   8,312,000 -28.8214  153.2600
18    Groceries Shop08 2015   4,053,000 -42.8826  147.3216
19    Groceries Shop09 2015   3,506,000 -27.4050  152.4424
20    Groceries Shop10 2015   3,492,000 -28.0632  148.2859

R Code Tried:

dat <- read.csv("Workbook1.csv")
lat <- dat$Latitude
lon <- dat$Longitude
nsales <- dat$Total.Sales
df <- as.data.frame(cbind(lon,lat))
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 4,
                      maptype = "satellite", scale = 2)
ggmap(mapgilbert) +
  geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
  guides(fill=FALSE, alpha=FALSE, size=FALSE)

Output enter image description here

I want to achieve an output like the Tableau one.


Solution

  • Try running this:

    lat <- dat$Latitude
    lon <- dat$Longitude
    nsales <- dat$Total.Sales
    df <- as.data.frame(cbind(lon,lat))
    mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)),     zoom = 4,
                          maptype = "satellite", scale = 2)
    ggmap(mapgilbert) +
      geom_point(data = dat, aes(x = Longitude, y = Latitude, fill = factor(Stores) , alpha = 0.8, size = Total.Sales), shape = 21) +
      guides(fill=FALSE, alpha=FALSE, size=FALSE)
    

    Facetting by Merchandise would be problematic here. You can try filtering to them and then rerunning the code.

    HTH