使用 R 绘制大小圆圈
Plotting sized circles using R
已经在 Tableau 中可视化了以下数据集,但需要知道如何使用 R 来实现它,因为我是新手。
数据集:
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 代码:
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)
输出
我想实现像 Tableau 那样的输出。
尝试运行这个:
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)
这里按商品分面会有问题。您可以尝试过滤它们,然后重新运行 代码。
HTH
已经在 Tableau 中可视化了以下数据集,但需要知道如何使用 R 来实现它,因为我是新手。
数据集:
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 代码:
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)
输出
我想实现像 Tableau 那样的输出。
尝试运行这个:
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)
这里按商品分面会有问题。您可以尝试过滤它们,然后重新运行 代码。
HTH