Использование двух наборов данных одной карты R ggmap

Я хочу иметь два разных набора данных на одной карте с помощью ggmap. Проблема в том, что когда я пытаюсь наложить оба набора данных, он стирает первый. Есть идеи, как это решить?

Dataset1 будет, например, номером патента на город в стране, а Dataset2 будет размером университетов в той же стране.

Мой код:

    map.ma <- get_map(location = 'Massachusetts', zoom = 8, color="bw")
    mapPoints <- ggmap(map.ma) + geom_point(aes(x = lon, y = lat, size = (sbir.cities1$SBIR)), data = sbir.cities1, alpha = .5, color="red")
    mapPoints2 <- mapPoints + scale_size_area(breaks = (c(1, 5, 10, 50, 100, 500)), labels = c(1, 5, 10, 50, 100, 500), name = "SBIR")
    mapPoints3 <- mapPoints2 + geom_point(aes(x = lon, y = lat, size = sqrt(ma.universities1$Enrollment)), data = ma.universities1, alpha = .5, color="blue")
    mapPoints4 <- mapPoints3 + scale_size_area(breaks = sqrt(c(5000, 10000, 15000, 20000, 25000, 30000)), labels = c(5000, 10000, 15000, 20000, 25000, 30000), name = "Enrollment")
    mapPoints4

Мои наборы данных:

    structure(list(X = c(1L, 3L, 4L, 5L, 6L), name = c("Acton", "Amesbury", 
"Amherst", "Andover", "Arlington"), SBIR = c(7L, 2L, 13L, 265L, 
6L), country.etc = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("#N/A", 
"MA"), class = "factor"), pop = structure(c(1L, 1L, 1L, 24L, 
10L), .Label = c("#N/A", "101342", "103085", "133313", "152095", 
"177973", "40063", "40441", "40565", "41246", "41520", "44473", 
"44690", "45127", "50698", "53579", "55066", "55862", "567759", 
"57377", "58407", "60784", "65103", "67715", "74802", "84969", 
"93128", "94039", "94945"), class = "factor"), lati = c(42.29, 
42.51, 42.23, 42.65, 42.42), long = c(-71.26, -70.55, -72.31, 
-71.14, -71.16), capital = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("#N/A", 
"0", "2"), class = "factor"), geocode = c("Acton Massachusetts", 
"Amesbury Massachusetts", "Amherst Massachusetts", "Andover Massachusetts", 
"Arlington Massachusetts"), lon = c(-71.43284, -70.9300376, -72.517, 
-71.1367953, -71.1564729), lat = c(42.4850931, 42.8583925, 42.367, 
42.6583356, 42.4153925)), .Names = c("X", "name", "SBIR", "country.etc", 
"pop", "lati", "long", "capital", "geocode", "lon", "lat"), row.names = c(89L, 
128L, 72L, 135L, 123L), class = "data.frame")

а также:

    structure(list(School = c("Boston University", "University of Massachusetts Amherst", 
"Harvard University", "Northeastern University", "University of Massachusetts Lowell"
), Location = structure(c(5L, 1L, 11L, 5L, 28L), .Label = c("Amherst", 
"Andover", "Bedford", "Beverly", "Boston", "Bourne", "Bridgewater", 
"Brighton", "Brockton", "Brookline", "Cambridge", "Chestnut Hill", 
"Chicopee", "Conway", "Dartmouth", "Dudley", "Easton", "Fall River", 
"Fitchburg", "Framingham", "Franklin", "Gardner", "Great Barrington", 
"Greenfield", "Haverhill", "Holyoke", "Longmeadow", "Lowell", 
"Lynn", "Medford", "Milton", "Needham", "Newton", "North Adams", 
"North Andover", "Northampton", "Norton", "Paxton", "Pittsfield", 
"Quincy", "Roxbury", "Salem", "South Hadley", "South Hamilton", 
"Springfield", "Swampscott", "Turners Falls", "Waltham", "Wellesley", 
"Wenham", "West Barnstable", "Westfield", "Weston", "Williamstown", 
"Worcester"), class = "factor"), Control = structure(c(2L, 3L, 
2L, 2L, 3L), .Label = c("For-profit", "Private", "Public"), class = "factor"), 
    Type = structure(c(7L, 7L, 7L, 7L, 7L), .Label = c("Associate\325s college", 
    "Baccalaureate college", "Baccalaureate/associate's college", 
    "Master's", "Master's university", "Master\325s university", 
    "Research university", "Special-focus institution"), class = "factor"), 
    Enrollment = c(32603L, 28518L, 28147L, 20053L, 16932L), geocode = c("Boston University Massachusetts", 
    "University of Massachusetts Amherst Massachusetts", "Harvard University Massachusetts", 
    "Northeastern University Massachusetts", "University of Massachusetts Lowell Massachusetts"
    ), lon = c(-71.1053991, -72.5267121, -71.1166601, -71.0891717, 
    -71.3340665), lat = c(42.3504997, 42.3911569, 42.3770029, 
    42.3398067, 42.6426529)), .Names = c("School", "Location", 
"Control", "Type", "Enrollment", "geocode", "lon", "lat"), row.names = c(NA, 
5L), class = "data.frame")

0 ответов

Другие вопросы по тегам