-3

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.

Frank
  • 66,179
  • 8
  • 96
  • 180
  • 1
    You can use for example `fill = Merchandise` and `size = Total.sales` inside the `aes`. – Jaap Mar 29 '16 at 13:15
  • 2
    btw: Why did you ask a new question instead of updating your [previous one](http://stackoverflow.com/questions/36282239/r-code-for-the-data-visualised-using-tableau)? – Jaap Mar 29 '16 at 13:17
  • Hi, thank you for your reply. I did update my previous one but it was "On Hold" so thought of posting again. – Arvind Suryanarayana Mar 29 '16 at 13:19
  • You might want to scale down your Total.sales otherwise it will be consuming the whole plot space. – zacdav Mar 29 '16 at 13:34

1 Answers1

0

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

sandoronodi
  • 315
  • 2
  • 12
  • 1
    Hi, thank you for your input. This worked perfectly! Also, I'm trying to add a legend to this by using the code: theme(legend.position = "bottom") and it brings up all the Total.Sales values individually. Is there a way i can group these and make the legend smaller? – Arvind Suryanarayana Mar 30 '16 at 11:47
  • Try to add this to the code: + theme(legend.position = "bottom", legend.text = element_text(colour="black", size = 6, face = "bold"), legend.title = element_text(colour="black", size=8, face="bold")) How do you want to group the legend? Btw. I warmly recommend the R graphics cookbook. you can find it here: http://ase.tufts.edu/bugs/guide/assets/R%20Graphics%20Cookbook.pdf most probably it covers what are you interested in :) – sandoronodi Mar 30 '16 at 13:13
  • Thanks again for the PDF. This is very helpful. I'm trying to group the sales data by range. I'm looking to group into categories like 0-100000 is a small circle, slightly bigger circle is 100000- 200000 and then so on. Do you have any inputs on this? – Arvind Suryanarayana Mar 31 '16 at 06:47