I want to (manually) chance the color of my bar plot. Right now, I used fill=group to determine the color scheme. However, I don't like the bright pink color and want to change this manually in a purple color, the rest of the colors are fine. How can I change color without altering the rest of the graph?
I used the command below for my bar plot:
ggplot(Dispersion3, aes(Batch.location, Number, fill=group))+
geom_bar(stat='identity')+
scale_x_discrete(guide = guide_axis(angle = 45))+
facet_grid(~factor(Season, levels=c("Winter1", "Spawn1", "Forage", "Winter2", "Spawn2"), labels = c("Winter-19/20", "Spawn-20", "Forage-20", "Winter-20/21", "Spawn-21")))+
scale_fill_discrete(name = "Distance from batch", labels = c("> 40 km", "30 - 40 km", "20 - 30 km", "10 - 20 km", "5 - 10 km", "< 5 km"))
[![enter image description here][1]][1]
Data=Dispersion3
structure(list(Transmitter = c("A69-1602-54311", "A69-1602-54311",
"A69-1602-54312", "A69-1602-54312", "A69-1602-54313", "A69-1602-54313",
"A69-1602-54314", "A69-1602-54314", "A69-1602-54315", "A69-1602-54315",
"A69-1602-54316", "A69-1602-54316", "A69-1602-54317", "A69-1602-54317",
"A69-1602-54318", "A69-1602-54318", "A69-1602-54319", "A69-1602-54319",
"A69-1602-54320", "A69-1602-54320", "A69-1602-54321", "A69-1602-54322",
"A69-1602-54323", "A69-1602-54323", "A69-1602-54324", "A69-1602-54325",
"A69-1602-54326", "A69-1602-54327", "A69-1602-54328", "A69-1602-59744",
"A69-1602-59745", "A69-1602-59745", "A69-1602-59745", "A69-1602-59745",
"A69-1602-59745", "A69-1602-59746", "A69-1602-59746", "A69-1602-59747",
"A69-1602-59747", "A69-1602-59747", "A69-1602-59747", "A69-1602-59747",
"A69-1602-59748", "A69-1602-59748", "A69-1602-59748", "A69-1602-59748",
"A69-1602-59749", "A69-1602-59750", "A69-1602-59750", "A69-1602-59750",
"A69-1602-59751", "A69-1602-59751", "A69-1602-59752", "A69-1602-59752",
"A69-1602-59753", "A69-1602-59753", "A69-1602-59753", "A69-1602-59753",
"A69-1602-59753", "A69-1602-59754", "A69-1602-59755", "A69-1602-59755",
"A69-1602-59755", "A69-1602-59755", "A69-1602-59755", "A69-1602-59756",
"A69-1602-59756", "A69-1602-59757", "A69-1602-59757", "A69-1602-59758",
"A69-1602-59758", "A69-1602-59758", "A69-1602-59758", "A69-1602-59758",
"A69-1602-59759", "A69-1602-59759", "A69-1602-59759", "A69-1602-59759",
"A69-1602-59760", "A69-1602-59760", "A69-1602-59761", "A69-1602-59761",
"A69-1602-59761", "A69-1602-59761", "A69-1602-59761", "A69-1602-59762",
"A69-1602-59762", "A69-1602-59763", "A69-1602-59763", "A69-1602-59763",
"A69-1602-59763", "A69-1602-59763", "A69-1602-59764", "A69-1602-59764",
"A69-1602-59764", "A69-1602-59764", "A69-1602-59764", "A69-1602-59765",
"A69-1602-59765", "A69-1602-59766", "A69-1602-59766", "A69-1602-59766",
"A69-1602-59766", "A69-1602-59767", "A69-1602-59767", "A69-1602-59767",
"A69-1602-59767", "A69-1602-59767", "A69-1602-59768", "A69-1602-59768",
"A69-1602-59768", "A69-1602-59768", "A69-1602-59768", "A69-1602-59769",
"A69-1602-59769", "A69-1602-59769", "A69-1602-59769", "A69-1602-59769",
"A69-1602-59770", "A69-1602-59770", "A69-1602-59771", "A69-1602-59771",
"A69-1602-59772", "A69-1602-59772", "A69-1602-59773", "A69-1602-59773",
"A69-1602-59773", "A69-1602-59773", "A69-1602-59773", "A69-1602-59774",
"A69-1602-59774", "A69-1602-59775", "A69-1602-59775", "A69-1602-59775",
"A69-1602-59775", "A69-1602-59775", "A69-1602-59776", "A69-1602-59776",
"A69-1602-59776", "A69-1602-59776", "A69-1602-59776", "A69-1602-59777",
"A69-1602-59777", "A69-1602-59777", "A69-1602-59777", "A69-1602-59777",
"A69-1602-59778", "A69-1602-59778", "A69-1602-59779", "A69-1602-59779",
"A69-1602-59779", "A69-1602-59779", "A69-1602-59780", "A69-1602-59780",
"A69-1602-59781", "A69-1602-59781", "A69-1602-59781", "A69-1602-59781",
"A69-1602-59781", "A69-1602-59782", "A69-1602-59782", "A69-1602-59783",
"A69-1602-59783", "A69-1602-59783", "A69-1602-59783", "A69-1602-59783",
"A69-1602-59784", "A69-1602-59784", "A69-1602-59784", "A69-1602-59784",
"A69-1602-59785", "A69-1602-59786", "A69-1602-59787", "A69-1602-59787",
"A69-1602-59787", "A69-1602-59787", "A69-1602-59787", "A69-1602-59788",
"A69-1602-59788", "A69-1602-59788", "A69-1602-59788", "A69-1602-59788",
"A69-1602-59789", "A69-1602-59789", "A69-1602-59789", "A69-1602-59789",
"A69-1602-59789", "A69-1602-59790", "A69-1602-59790", "A69-1602-59791",
"A69-1602-59791", "A69-1602-59792", "A69-1602-59793", "A69-1602-59793",
"A69-1602-59793", "A69-1602-59793", "A69-1602-59794", "A69-1602-59794",
"A69-1602-59795", "A69-1602-59795", "A69-1602-59796", "A69-1602-59796",
"A69-1602-59796", "A69-1602-59796", "A69-1602-59796", "A69-1602-59797",
"A69-1602-59797", "A69-1602-59798", "A69-1602-59798", "A69-1602-59799",
"A69-1602-59799", "A69-1602-59799", "A69-1602-59799", "A69-1602-59799",
"A69-1602-59800", "A69-1602-59800", "A69-1602-59801", "A69-1602-59801",
"A69-1602-59801", "A69-1602-59801", "A69-1602-59801", "A69-1602-59802",
"A69-1602-59802", "A69-1602-59803", "A69-1602-59803", "A69-1602-59803",
"A69-1602-59803", "A69-1602-59803", "A69-1602-59804", "A69-1602-59804",
"A69-1602-59805", "A69-1602-59805", "A69-1602-59806", "A69-1602-59806",
"A69-1602-59807", "A69-1602-59807", "A69-1602-59807", "A69-1602-59808",
"A69-1602-59808", "A69-1602-59809", "A69-1602-59809", "A69-1602-59810",
"A69-1602-59810", "A69-1602-59810", "A69-1602-59811", "A69-1602-59811",
"A69-1602-59812", "A69-1602-59812", "A69-1602-59813", "A69-1602-59813",
"A69-1602-59814", "A69-1602-59814", "A69-1602-59814", "A69-1602-59814",
"A69-1602-59815", "A69-1602-59815", "A69-1602-59815", "A69-1602-59815",
"A69-1602-59816", "A69-1602-59817", "A69-1602-59819", "A69-1602-59819",
"A69-1602-59820", "A69-1602-59821", "A69-1602-59821", "A69-1602-59822",
"A69-1602-59823", "A69-1602-59823", "A69-1602-59824", "A69-1602-59825",
"A69-1602-59826", "A69-1602-59826", "A69-1602-59826", "A69-1602-59827",
"A69-1602-59827", "A69-1602-59828", "A69-1602-59828", "A69-1602-59828",
"A69-1602-59828", "A69-1602-59828", "A69-1602-59829", "A69-1602-59829",
"A69-1602-59830", "A69-1602-59831", "A69-1602-59831", "A69-1602-59831",
"A69-1602-59831", "A69-1602-59831", "A69-1602-59832", "A69-1602-59833",
"A69-1602-59834", "A69-1602-59835", "A69-1602-59835", "A69-1602-59835",
"A69-1602-59835", "A69-1602-59835", "A69-1602-59836", "A69-1602-59836",
"A69-1602-59837", "A69-1602-59837", "A69-1602-59838", "A69-1602-59839",
"A69-1602-59839", "A69-1602-59840", "A69-1602-59840", "A69-1602-59841",
"A69-1602-59841", "A69-1602-59842", "A69-1602-59843", "A69-1602-59843",
"A69-1602-59843"), Season = c("Forage", "Spawn2", "Forage", "Spawn2",
"Forage", "Spawn2", "Forage", "Spawn2", "Forage", "Spawn2", "Forage",
"Spawn2", "Forage", "Spawn2", "Forage", "Spawn2", "Forage", "Spawn2",
"Forage", "Spawn2", "Spawn2", "Spawn2", "Forage", "Spawn2", "Spawn2",
"Spawn2", "Spawn2", "Spawn2", "Spawn2", "Winter1", "Forage",
"Spawn1", "Spawn2", "Winter1", "Winter2", "Spawn1", "Winter1",
"Forage", "Spawn1", "Spawn2", "Winter1", "Winter2", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Spawn1", "Forage", "Winter1",
"Winter2", "Spawn1", "Winter1", "Spawn1", "Winter1", "Forage",
"Spawn1", "Spawn2", "Winter1", "Winter2", "Winter1", "Forage",
"Spawn1", "Spawn2", "Winter1", "Winter2", "Spawn1", "Winter1",
"Spawn1", "Winter1", "Forage", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Forage", "Spawn1", "Winter1", "Winter2", "Spawn1",
"Winter1", "Forage", "Spawn1", "Spawn2", "Winter1", "Winter2",
"Spawn1", "Winter1", "Forage", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Forage", "Spawn1", "Spawn2", "Winter1", "Winter2",
"Spawn1", "Winter1", "Spawn1", "Spawn2", "Winter1", "Winter2",
"Forage", "Spawn1", "Spawn2", "Winter1", "Winter2", "Forage",
"Spawn1", "Spawn2", "Winter1", "Winter2", "Forage", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Spawn1", "Winter1", "Spawn1",
"Winter1", "Spawn1", "Winter1", "Forage", "Spawn1", "Spawn2",
"Winter1", "Winter2", "Spawn1", "Winter1", "Forage", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Forage", "Spawn1", "Spawn2",
"Winter1", "Winter2", "Forage", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Spawn1", "Winter1", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Spawn1", "Winter1", "Forage", "Spawn1", "Spawn2",
"Winter1", "Winter2", "Spawn1", "Winter1", "Forage", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Forage", "Spawn1", "Spawn2",
"Winter1", "Winter1", "Winter1", "Forage", "Spawn1", "Spawn2",
"Winter1", "Winter2", "Forage", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Forage", "Spawn1", "Spawn2", "Winter1", "Winter2",
"Spawn1", "Winter1", "Spawn1", "Winter1", "Winter1", "Forage",
"Spawn1", "Winter1", "Winter2", "Spawn1", "Winter1", "Spawn1",
"Winter1", "Forage", "Spawn1", "Spawn2", "Winter1", "Winter2",
"Spawn1", "Winter1", "Spawn1", "Winter1", "Forage", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Spawn1", "Winter1", "Forage",
"Spawn1", "Spawn2", "Winter1", "Winter2", "Spawn1", "Winter1",
"Forage", "Spawn1", "Spawn2", "Winter1", "Winter2", "Spawn1",
"Winter1", "Spawn1", "Winter1", "Spawn1", "Winter1", "Forage",
"Spawn1", "Winter1", "Spawn1", "Winter1", "Spawn1", "Winter1",
"Forage", "Spawn1", "Winter1", "Spawn1", "Winter1", "Spawn1",
"Winter1", "Spawn1", "Winter1", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Spawn1", "Spawn2", "Winter1", "Winter2", "Winter1",
"Winter1", "Spawn1", "Winter1", "Winter1", "Spawn1", "Winter1",
"Winter1", "Spawn1", "Winter1", "Winter1", "Winter1", "Spawn1",
"Winter1", "Winter2", "Spawn1", "Winter1", "Forage", "Spawn1",
"Spawn2", "Winter1", "Winter2", "Forage", "Spawn1", "Winter1",
"Forage", "Spawn1", "Spawn2", "Winter1", "Winter2", "Winter1",
"Winter1", "Winter1", "Forage", "Spawn1", "Spawn2", "Winter1",
"Winter2", "Spawn1", "Winter1", "Spawn1", "Winter1", "Winter1",
"Spawn1", "Winter1", "Spawn1", "Winter1", "Spawn1", "Winter1",
"Winter1", "Forage", "Spawn1", "Winter1"), Batch.location = structure(c(8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
3L, 3L, 3L, 3L, 3L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Den Oever", "Medemblik",
"Enkhuizen", "Stavoren", "Lemmer", "Ketelhaven", "Lelystad",
"Markerwadden"), class = "factor"), `max distance` = c(2.09861304168527,
2.52186862327424, 2.09861304168527, 2.09861304168527, 2.06773203256743,
2.09861304168527, 2.09861304168527, 2.52186862327424, 2.06773203256743,
2.09861304168527, 2.09861304168527, 2.09861304168527, 0.207052365336615,
2.09861304168527, 2.09861304168527, 2.09861304168527, 2.09861304168527,
2.27221768516951, 2.09861304168527, 2.52186862327424, 2.09861304168527,
2.52186862327424, 2.09861304168527, 2.52186862327424, 0.207052365336615,
2.52186862327424, 0.207052365336615, 2.09861304168527, 2.09861304168527,
2.55827101689345, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 29.6222537752041, 2.55827101689345,
0, 2.55827101689345, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 13.6078290874409, 2.55827101689345, 0, 4.07525961740185,
14.7442644338329, 0, 14.7442644338329, 14.7442644338329, 14.7442644338329,
14.7442644338329, 0, 0, 0, 0, 0, 0, 3.67357267678004, 14.7442644338329,
31.8861260921355, 31.8861260921355, 14.7442644338329, 14.7442644338329,
0, 3.67357267678004, 31.8861260921355, 0, 0, 0, 0, 14.1891547888285,
3.67357267678004, 13.6078290874409, 53.9604508112108, 39.9833461407132,
13.6078290874409, 1.60673719243843, 1.60673719243843, 18.8755486336044,
37.1477457727004, 37.1477457727004, 1.60673719243843, 0, 2.93233568869472,
1.60673719243843, 0, 1.60673719243843, 0, 18.8755486336044, 0,
0, 2.93233568869472, 2.93233568869472, 2.93233568869472, 2.93233568869472,
2.93233568869472, 2.93233568869472, 13.6078290874409, 13.6078290874409,
2.93233568869472, 0, 0, 2.93233568869472, 2.93233568869472, 2.93233568869472,
2.93233568869472, 0, 2.93233568869472, 2.93233568869472, 2.93233568869472,
2.93233568869472, 0, 0, 0, 0, 0, 22.0689264444271, 22.0689264444271,
21.6573593129425, 0, 0, 0, 0, 21.6573593129425, 21.6573593129425,
0, 0, 27.1352921526802, 27.1352921526802, 0, 21.6573593129425,
21.6573593129425, 0, 0, 0, 0, 0, 17.2740564735626, 0, 18.8755486336044,
0, 0, 0, 0, 22.0689264444271, 0, 34.0126665945869, 31.5589537736477,
31.5589537736477, 22.1776822695344, 0, 22.1776822695344, 31.389797027264,
44.5900705020792, 43.3976533332777, 31.389797027264, 43.3976533332777,
14.8691518778998, 14.8691518778998, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 2.55827101689345, 14.5827981937255,
15.7089215225545, 14.5827981937255, 2.55827101689345, 2.55827101689345,
2.55827101689345, 0, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 0, 0, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 2.55827101689345, 2.55827101689345,
2.55827101689345, 2.55827101689345, 17.5361439864551, 0, 17.5361439864551,
31.5589537736477, 0, 17.5361439864551, 17.5361439864551, 0, 0,
30.1390542608465, 31.5589537736477, 17.5361439864551, 0, 22.1776822695344,
38.0419064223524, 22.1776822695344, 26.4325286192825, 38.0419064223524,
0, 0, 0, 17.5361439864551, 17.5361439864551, 0, 0, 17.5361439864551,
17.5361439864551, 0, 17.5361439864551, 0, 0, 0, 30.1390542608465,
0, 30.1390542608465, 0, 1.48108027988229, 1.48108027988229, 17.6313494625488,
30.1390542608465, 18.5565893657245, 29.6361491030785, 0, 17.5361439864551,
7.13622984428536, 1.48108027988229, 22.1776822695344, 22.1776822695344,
35.5520908555987, 21.0650298743005, 59.7128353277037, 31.5589537736477,
17.5361439864551, 17.5361439864551, 2.25656968299054, 2.25656968299054,
2.25656968299054, 2.25656968299054, 0, 0, 0, 0, 52.5465855455931,
21.2040865946565, 2.25656968299054, 0, 0, 0, 21.2040865946565,
0, 0, 0, 0, 38.2165754172804, 0, 0, 0, 0, 0, 31.8861260921355,
21.2040865946565, 21.2040865946565, 21.2040865946565, 33.4969050950683,
26.4925842074686, 0, 0, 0, 2.25656968299054, 2.25656968299054,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.25656968299054, 0, 21.2040865946565,
21.2040865946565, 21.2040865946565, 21.2040865946565, 21.2040865946565,
21.2040865946565, 21.2040865946565, 64.1655009571088, 43.8757964958802,
0, 21.6264847096301, 21.6264847096301, 21.2040865946565), group = structure(c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 4L, 6L, 6L, 6L, 4L, 6L,
4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 4L, 2L, 2L, 4L, 4L,
6L, 6L, 2L, 6L, 6L, 6L, 6L, 4L, 6L, 4L, 1L, 2L, 4L, 6L, 6L, 4L,
2L, 2L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 4L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 3L, 3L, 6L, 6L,
3L, 3L, 6L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 4L, 6L, 4L, 6L, 6L, 6L,
6L, 3L, 6L, 2L, 2L, 2L, 3L, 6L, 3L, 2L, 1L, 1L, 2L, 1L, 4L, 4L,
6L, 6L, 6L, 6L, 6L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 4L, 6L, 4L, 2L, 6L, 4L, 4L, 6L, 6L, 2L, 2L, 4L, 6L,
3L, 2L, 3L, 3L, 2L, 6L, 6L, 6L, 4L, 4L, 6L, 6L, 4L, 4L, 6L, 4L,
6L, 6L, 6L, 2L, 6L, 2L, 6L, 6L, 6L, 4L, 2L, 4L, 3L, 6L, 4L, 5L,
6L, 3L, 3L, 2L, 3L, 1L, 2L, 4L, 4L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 1L, 3L, 6L, 6L, 6L, 6L, 3L, 6L, 6L, 6L, 6L, 2L, 6L, 6L, 6L,
6L, 6L, 2L, 3L, 3L, 3L, 2L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L, 6L, 3L, 3L, 3L), .Label = c("6", "5", "4", "3", "2",
"1"), class = "factor"), Number = c(1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1)), row.names = c(NA, -311L), class = c("tbl_df",
"tbl", "data.frame"))
[1]: https://i.stack.imgur.com/5D1CE.png
The default colors that scale_fill_discrete() uses for 6 levels can be generated using scales::hue_pal():
> my_colors = scales::hue_pal()(6)
> my_colors
[1] "#F8766D" "#B79F00" "#00BA38" "#00BFC4" "#619CFF" "#F564E3"
The last color corresponds to the bright pink that you don't like. You can change it to purple:
my_colors[6] = "#C77CFF"
Then, use scale_fill_manual to use this set of colors:
ggplot(Dispersion3, aes(Batch.location, Number, fill=group))+
geom_bar(stat='identity')+
scale_x_discrete(guide = guide_axis(angle = 45))+
facet_grid(~factor(Season, levels=c("Winter1", "Spawn1", "Forage", "Winter2", "Spawn2"), labels = c("Winter-19/20", "Spawn-20", "Forage-20", "Winter-20/21", "Spawn-21")))+
scale_fill_manual(
name = "Distance from batch",
labels = c("> 40 km", "30 - 40 km", "20 - 30 km", "10 - 20 km", "5 - 10 km", "< 5 km"),
values = my_colors
)
Related
I'm new to cuML and I have a decision tree classifier using scikit learn. I would like to perform some hyperparameter search using the GPU, so I started looking cuML. There is no DecisionTreeClassifier in cuML, but it can be reproduced by using RandomForestClassifier with 1 tree and no bootstrap, as far as I read on other SO posts.
My problem is how can I extract the tree and all the rules (the leafs and nodes) using cuML RandomForestClassifier? Or I should be looking to other algorithms like XGBoost?
Access to the underlying decision trees or information isn't necessary to do hyperparameter optimization.
With that said, you can access summary information about the underlying trees and leaf predictions like this:
from cuml.ensemble import RandomForestClassifier
from cuml.datasets import make_classification
N = 100
K = 10
X, y = make_classification(
n_samples=N,
n_features=K,
n_informative=K,
n_redundant=0
)
clf = RandomForestClassifier(n_estimators=2)
clf.fit(X, y)
print(clf.get_summary_text())
print(clf.get_detailed_text())
print(clf.get_json())
Forest has 2 trees, max_depth 16, and max_leaves -1
Tree #0
Decision Tree depth --> 9 and n_leaves --> 18
Tree Fitting - Overall time --> 1.216 milliseconds
Tree #1
Decision Tree depth --> 7 and n_leaves --> 16
Tree Fitting - Overall time --> 1.919 milliseconds
Forest has 2 trees, max_depth 16, and max_leaves -1
Tree #0
Decision Tree depth --> 9 and n_leaves --> 18
Tree Fitting - Overall time --> 1.216 milliseconds
└(colid: 7, quesval: 2.73323, best_metric_val: 0.0407427)
├(colid: 9, quesval: -0.233239, best_metric_val: 0.116631)
│ ├(colid: 2, quesval: -1.48028, best_metric_val: 0.045858)
│ │ ├(colid: 8, quesval: -1.14041, best_metric_val: 0.28125)
│ │ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ │ └(colid: 1, quesval: 0.720062, best_metric_val: 0.375)
│ │ │ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ │ │ └(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [0, 1], best_metric_val: 0)
│ └(colid: 3, quesval: -1.01601, best_metric_val: 0.313368)
│ ├(colid: 8, quesval: 1.68195, best_metric_val: 0.0131944)
│ │ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ │ └(colid: 6, quesval: -0.458985, best_metric_val: 0.32)
│ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(colid: 7, quesval: -2.86422, best_metric_val: 0.126263)
│ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(colid: 8, quesval: 1.3618, best_metric_val: 0.0198347)
│ ├(colid: 9, quesval: 1.96266, best_metric_val: 0.142222)
│ │ ├(colid: 5, quesval: -0.427346, best_metric_val: 0.0308642)
│ │ │ ├(colid: 8, quesval: -0.295362, best_metric_val: 0.125)
│ │ │ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ │ │ └(colid: 6, quesval: 1.99819, best_metric_val: 0.5)
│ │ │ │ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ │ │ │ └(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ │ └(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(leaf, prediction: [0, 1], best_metric_val: 0)
└(colid: 3, quesval: 1.4614, best_metric_val: 0.239645)
├(leaf, prediction: [1, 0], best_metric_val: 0)
└(colid: 7, quesval: 3.80204, best_metric_val: 0.125)
├(leaf, prediction: [0, 1], best_metric_val: 0)
└(colid: 8, quesval: 0.637938, best_metric_val: 0.5)
├(leaf, prediction: [0, 1], best_metric_val: 0)
└(leaf, prediction: [1, 0], best_metric_val: 0)
Tree #1
Decision Tree depth --> 7 and n_leaves --> 16
Tree Fitting - Overall time --> 1.919 milliseconds
└(colid: 8, quesval: -1.19294, best_metric_val: 0.111478)
├(colid: 7, quesval: -2.32102, best_metric_val: 0.0867768)
│ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(leaf, prediction: [0, 1], best_metric_val: 0)
└(colid: 3, quesval: 0.590359, best_metric_val: 0.180291)
├(colid: 6, quesval: -2.11692, best_metric_val: 0.126613)
│ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ └(colid: 5, quesval: -1.94796, best_metric_val: 0.0655193)
│ ├(colid: 6, quesval: 1.18255, best_metric_val: 0.489796)
│ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(colid: 8, quesval: 3.48108, best_metric_val: 0.0196773)
│ ├(colid: 5, quesval: 0.71779, best_metric_val: 0.00283446)
│ │ ├(colid: 4, quesval: 1.85633, best_metric_val: 1.19209e-07)
│ │ │ ├(leaf, prediction: [1, 0], best_metric_val: 0)
│ │ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ │ └(colid: 5, quesval: 0.815552, best_metric_val: 0.152778)
│ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(colid: 9, quesval: 0.690919, best_metric_val: 0.5)
│ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ └(leaf, prediction: [1, 0], best_metric_val: 0)
└(colid: 6, quesval: 2.16413, best_metric_val: 0.071035)
├(colid: 7, quesval: 3.80204, best_metric_val: 0.0818594)
│ ├(colid: 9, quesval: 1.33454, best_metric_val: 0.02)
│ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(colid: 5, quesval: 0.0840077, best_metric_val: 0.375)
│ │ ├(leaf, prediction: [0, 1], best_metric_val: 0)
│ │ └(leaf, prediction: [1, 0], best_metric_val: 0)
│ └(leaf, prediction: [1, 0], best_metric_val: 0)
└(leaf, prediction: [1, 0], best_metric_val: 0)
[
{"nodeid": 0, "split_feature": 7, "split_threshold": 2.7332263, "gain": 0.0407427214, "instance_count": 100, "yes": 1, "no": 2, "children": [
{"nodeid": 1, "split_feature": 9, "split_threshold": -0.233238578, "gain": 0.116630867, "instance_count": 87, "yes": 3, "no": 4, "children": [
{"nodeid": 3, "split_feature": 2, "split_threshold": -1.48028064, "gain": 0.0458579995, "instance_count": 39, "yes": 7, "no": 8, "children": [
{"nodeid": 7, "split_feature": 8, "split_threshold": -1.1404053, "gain": 0.28125, "instance_count": 8, "yes": 13, "no": 14, "children": [
{"nodeid": 13, "leaf_value": [0, 1], "instance_count": 4},
{"nodeid": 14, "split_feature": 1, "split_threshold": 0.720061541, "gain": 0.375, "instance_count": 4, "yes": 21, "no": 22, "children": [
{"nodeid": 21, "leaf_value": [1, 0], "instance_count": 3},
{"nodeid": 22, "leaf_value": [0, 1], "instance_count": 1}
]}
]},
{"nodeid": 8, "leaf_value": [0, 1], "instance_count": 31}
]},
{"nodeid": 4, "split_feature": 3, "split_threshold": -1.01600909, "gain": 0.313368142, "instance_count": 48, "yes": 9, "no": 10, "children": [
{"nodeid": 9, "split_feature": 8, "split_threshold": 1.68195295, "gain": 0.0131943803, "instance_count": 24, "yes": 15, "no": 16, "children": [
{"nodeid": 15, "leaf_value": [1, 0], "instance_count": 19},
{"nodeid": 16, "split_feature": 6, "split_threshold": -0.458984971, "gain": 0.320000023, "instance_count": 5, "yes": 23, "no": 24, "children": [
{"nodeid": 23, "leaf_value": [0, 1], "instance_count": 1},
{"nodeid": 24, "leaf_value": [1, 0], "instance_count": 4}
]}
]},
{"nodeid": 10, "split_feature": 7, "split_threshold": -2.86421776, "gain": 0.126262575, "instance_count": 24, "yes": 17, "no": 18, "children": [
{"nodeid": 17, "leaf_value": [1, 0], "instance_count": 2},
{"nodeid": 18, "split_feature": 8, "split_threshold": 1.36179876, "gain": 0.0198347215, "instance_count": 22, "yes": 25, "no": 26, "children": [
{"nodeid": 25, "split_feature": 9, "split_threshold": 1.96266103, "gain": 0.142222196, "instance_count": 10, "yes": 27, "no": 28, "children": [
{"nodeid": 27, "split_feature": 5, "split_threshold": -0.427345634, "gain": 0.0308641735, "instance_count": 9, "yes": 29, "no": 30, "children": [
{"nodeid": 29, "split_feature": 8, "split_threshold": -0.295361876, "gain": 0.125, "instance_count": 4, "yes": 31, "no": 32, "children": [
{"nodeid": 31, "leaf_value": [0, 1], "instance_count": 2},
{"nodeid": 32, "split_feature": 6, "split_threshold": 1.99819326, "gain": 0.5, "instance_count": 2, "yes": 33, "no": 34, "children": [
{"nodeid": 33, "leaf_value": [1, 0], "instance_count": 1},
{"nodeid": 34, "leaf_value": [0, 1], "instance_count": 1}
]}
]},
{"nodeid": 30, "leaf_value": [0, 1], "instance_count": 5}
]},
{"nodeid": 28, "leaf_value": [1, 0], "instance_count": 1}
]},
{"nodeid": 26, "leaf_value": [0, 1], "instance_count": 12}
]}
]}
]}
]},
{"nodeid": 2, "split_feature": 3, "split_threshold": 1.46139979, "gain": 0.239644989, "instance_count": 13, "yes": 5, "no": 6, "children": [
{"nodeid": 5, "leaf_value": [1, 0], "instance_count": 9},
{"nodeid": 6, "split_feature": 7, "split_threshold": 3.8020432, "gain": 0.125, "instance_count": 4, "yes": 11, "no": 12, "children": [
{"nodeid": 11, "leaf_value": [0, 1], "instance_count": 2},
{"nodeid": 12, "split_feature": 8, "split_threshold": 0.637937546, "gain": 0.5, "instance_count": 2, "yes": 19, "no": 20, "children": [
{"nodeid": 19, "leaf_value": [0, 1], "instance_count": 1},
{"nodeid": 20, "leaf_value": [1, 0], "instance_count": 1}
]}
]}
]}
]},
{"nodeid": 0, "split_feature": 8, "split_threshold": -1.19294095, "gain": 0.111478344, "instance_count": 100, "yes": 1, "no": 2, "children": [
{"nodeid": 1, "split_feature": 7, "split_threshold": -2.3210218, "gain": 0.0867768154, "instance_count": 22, "yes": 3, "no": 4, "children": [
{"nodeid": 3, "leaf_value": [1, 0], "instance_count": 1},
{"nodeid": 4, "leaf_value": [0, 1], "instance_count": 21}
]},
{"nodeid": 2, "split_feature": 3, "split_threshold": 0.590358853, "gain": 0.180290893, "instance_count": 78, "yes": 5, "no": 6, "children": [
{"nodeid": 5, "split_feature": 6, "split_threshold": -2.1169188, "gain": 0.12661314, "instance_count": 56, "yes": 7, "no": 8, "children": [
{"nodeid": 7, "leaf_value": [0, 1], "instance_count": 5},
{"nodeid": 8, "split_feature": 5, "split_threshold": -1.94796324, "gain": 0.065519318, "instance_count": 51, "yes": 11, "no": 12, "children": [
{"nodeid": 11, "split_feature": 6, "split_threshold": 1.18254995, "gain": 0.489795923, "instance_count": 7, "yes": 15, "no": 16, "children": [
{"nodeid": 15, "leaf_value": [0, 1], "instance_count": 4},
{"nodeid": 16, "leaf_value": [1, 0], "instance_count": 3}
]},
{"nodeid": 12, "split_feature": 8, "split_threshold": 3.48108315, "gain": 0.0196772516, "instance_count": 44, "yes": 17, "no": 18, "children": [
{"nodeid": 17, "split_feature": 5, "split_threshold": 0.717789888, "gain": 0.00283446093, "instance_count": 42, "yes": 21, "no": 22, "children": [
{"nodeid": 21, "split_feature": 4, "split_threshold": 1.85632861, "gain": 1.1920929e-07, "instance_count": 30, "yes": 27, "no": 28, "children": [
{"nodeid": 27, "leaf_value": [1, 0], "instance_count": 19},
{"nodeid": 28, "leaf_value": [1, 0], "instance_count": 11}
]},
{"nodeid": 22, "split_feature": 5, "split_threshold": 0.815551639, "gain": 0.152777761, "instance_count": 12, "yes": 29, "no": 30, "children": [
{"nodeid": 29, "leaf_value": [0, 1], "instance_count": 1},
{"nodeid": 30, "leaf_value": [1, 0], "instance_count": 11}
]}
]},
{"nodeid": 18, "split_feature": 9, "split_threshold": 0.690918803, "gain": 0.5, "instance_count": 2, "yes": 23, "no": 24, "children": [
{"nodeid": 23, "leaf_value": [0, 1], "instance_count": 1},
{"nodeid": 24, "leaf_value": [1, 0], "instance_count": 1}
]}
]}
]}
]},
{"nodeid": 6, "split_feature": 6, "split_threshold": 2.1641295, "gain": 0.0710349679, "instance_count": 22, "yes": 9, "no": 10, "children": [
{"nodeid": 9, "split_feature": 7, "split_threshold": 3.8020432, "gain": 0.0818593949, "instance_count": 21, "yes": 13, "no": 14, "children": [
{"nodeid": 13, "split_feature": 9, "split_threshold": 1.33453584, "gain": 0.0200000368, "instance_count": 20, "yes": 19, "no": 20, "children": [
{"nodeid": 19, "leaf_value": [0, 1], "instance_count": 16},
{"nodeid": 20, "split_feature": 5, "split_threshold": 0.08400774, "gain": 0.375, "instance_count": 4, "yes": 25, "no": 26, "children": [
{"nodeid": 25, "leaf_value": [0, 1], "instance_count": 3},
{"nodeid": 26, "leaf_value": [1, 0], "instance_count": 1}
]}
]},
{"nodeid": 14, "leaf_value": [1, 0], "instance_count": 1}
]},
{"nodeid": 10, "leaf_value": [1, 0], "instance_count": 1}
]}
]}
]}
]
I have a problem v-datatable rendering each time I change a v-select.
I´d like it render only when I click in a button, I created to do fetch data from server.
Here is the codepen: https://codepen.io/luizalves/pen/VwrwXwE?editors=101
For now, it´s rendering all times I change the v-select.
data:()=>({
grupos: [
{ id: 1, nome: 'Diário', ffi: 'YYYY-MM-DD', fff: 'DD-MM-YYYY' },
{ id: 2, nome: 'Mensal', ffi: 'YYYY-MM', fff: 'MM-YYYY' },
{ id: 3, nome: 'Anual', ffi: 'YYYY', fff: 'YYYY' },
],
grupo:1
headers: [
{ text: 'Data', value: 'label', sortable: false },
{ text: 'Total(R$) ', value: 'total', sortable: false },
],
)}
// data-table
<v-select
v-model="grupo"
label="Grupado por"
:items="grupos"
item-text="nome"
item-value="id"
class="purple-input"
/>
<v-btn
class="mt-1 mr-3"
color="info"
#click.stop="getEstatisticasPeriodo()"
>
Pesquisar
</v-btn>
<v-data-table
:headers="headers"
:items="result_dados"
:items-per-page="3"
:footer-props="{
'items-per-page-options': [3, 5, 10, 20, 30, 40, 50],
}"
class="elevation-1"
>
<template
v-for="(header, i) in headers"
#[`item.${header.value}`]="{ item }"
>
<template v-if="header.value !== 'actions'">
<span :key="i">
{{ formatColumn(item, header) }}
</span>
</template>
</template>
</v-data-table>
methods: {
formatColumn(item, col) {
if (!item[col.value]) return ''
if (['total'].includes(col.value)) {
const formatado = Number(item[col.value]).toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL',
})
return formatado
}
if (['label'].includes(col.value)) {
const ffi = this.grupos.find((m) => m.id == this.grupo).ffi
const fff = this.grupos.find((m) => m.id == this.grupo).fff
return this.$moment(item[col.value], ffi).format(fff)
} else return item[col.value]
},
getEstatisticasPeriodo(){
// fetch api data
}
....
Any data value you access in formatCalories will be added the list of watched values. When the value changes, it will re-render the view and call formatCalories. To solve that issue, I just created a selectValue property that is only set when the button is clicked.
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
group: 1,
selectValue: 1,
groups: [
{ id: 1, name: 'day'},
{ id: 2, name: 'month' },
{ id: 3, name: 'year' },
],
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
],
}
},
methods: {
onSubmit() {
this.selectValue = this.$refs.select.value;
},
formatCalories(calories) {
const suffix = {
1: '-red',
2: '-orange',
3: '-green'
};
return calories + suffix[this.selectValue];
}
},
})
<div id="app">
<v-app id="inspire">
<v-row>
<v-col cols='3'>
<v-btn elevation="2" #click="onSubmit"> Submit </v-btn>
<v-select
v-model="group"
label="Grouped by"
:items="groups"
item-text="name"
item-value="id"
class="purple-input"
ref="select"
/>
</v-col>
</v-row>
<v-data-table
:headers="headers"
:items="desserts"
class="elevation-1"
>
<template v-slot:item.calories="{ item }">
{{ formatCalories(item.calories) }}
</template>
</v-data-table>
</v-app>
</div>
{'_id': ObjectId('619f4e58b1a936e640635e97'), 'OrderDate': '01-01-2020', 'Region': 'East', 'City': 'Boston', 'Category': 'Bars', 'Product': 'Carrot', 'Quantity': '33', 'UnitPrice': '1.77', 'TotalPrice': 58.0, '': 'Sum of TotalPrice'}
{'_id': ObjectId('619f4e58b1a936e640635e98'), 'OrderDate': '04-01-2020', 'Region': 'East', 'City': 'Boston', 'Category': 'Crackers', 'Product': 'Whole Wheat', 'Quantity': '87', 'UnitPrice': '3.49', 'TotalPrice': 303.0, '': '17988.66'}
{'_id': ObjectId('619f4e58b1a936e640635e99'), 'OrderDate': '07-01-2020', 'Region': 'West', 'City': 'Los Angeles', 'Category': 'Cookies', 'Product': 'Chocolate Chip', 'Quantity': '58', 'UnitPrice': '1.87', 'TotalPrice': 108.46, '': '15336.92'}
{'_id': ObjectId('619f4e58b1a936e640635e9a'), 'OrderDate': '10-01-2020', 'Region': 'East', 'City': 'New York', 'Category': 'Cookies', 'Product': 'Chocolate Chip', 'Quantity': '82', 'UnitPrice': '1.87', 'TotalPrice': 153.34, '': '33325.58'}
{'_id': ObjectId('619f4e58b1a936e640635e9b'), 'OrderDate': '13-01-2020', 'Region': 'East', 'City': 'Boston', 'Category': 'Cookies', 'Product': 'Arrowroot', 'Quantity': '38', 'UnitPrice': '2.18', 'TotalPrice': 82.84}
{'_id': ObjectId('619f4e58b1a936e640635e9c'), 'OrderDate': '16-01-2020', 'Region': 'East', 'City': 'Boston', 'Category': 'Bars', 'Product': 'Carrot', 'Quantity': '54', 'UnitPrice': '1.77', 'TotalPrice': 95.58}
{'_id': ObjectId('619f4e58b1a936e640635e9d'), 'OrderDate': '19-01-2020', 'Region': 'East', 'City': 'Boston', 'Category': 'Crackers', 'Product': 'Whole Wheat', 'Quantity': '149', 'UnitPrice': '3.49', 'TotalPrice': 520.01}
{'_id': ObjectId('619f4e58b1a936e640635e9e'), 'OrderDate': '22-01-2020', 'Region': 'West', 'City': 'Los Angeles', 'Category': 'Bars', 'Product': 'Carrot', 'Quantity': '51', 'UnitPrice': '1.77', 'TotalPrice': 90.27}
w=db.sales.count_documents({"Region":"West"})
e=db.sales.count_documents({"Region":"East"})
print("Total count of orders in East region and West region are",w,"and",e)
a=db.sales.aggregate([{"$project":{"Region":1,"City":1}}])
for i in a:
print(i)
Try this instead, Refer https://mongoplayground.net/p/d4L-QQXh1Id
db.collection.aggregate([
{
"$group": {
"_id": {
"Region": "$Region",
"City": "$City"
},
"Total Amount": {
"$sum": "$TotalPrice"
},
"count": {
"$sum": 1
}
},
},
{
"$project": {
"_id": 0,
"Cities": "$_id.City",
"Total Count": "$count",
"Total Amount": "$Total Amount"
}
}
])
Suppose I have the following data:
import pandas pd
data = [44.5, 27.0, 22.0, 23.0, 23.0, 24.0, 23.0, 21.0, 22.0, 20.0, 22.0, 19.0, 20.0, 19.0, 20.0, 20.0, 18.0, 18.0, 18.0, 16.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.5, 16.0, 16.0, 16.0, 16.0, 21.0, 18.0, 17.0, 18.0, 16.0, 17.0, 16.0, 16.0, 16.0, 17.0, 17.0, 16.0, 16.0, 16.0, 16.0, 17.0, 16.0, 16.0, 16.0, 16.0, 17.0, 17.0, 17.0, 17.0, 19.0, 18.0, 18.0, 17.0, 18.0, 19.0, 54.0, 37.0, 31.0, 30.0, 30.0, 30.0, 28.0, 26.0, 27.5, 25.0, 26.0, 26.0, 26.0, 26.0, 25.0, 30.0, 29.0, 26.0, 28.0, 26.0, 27.0, 25.0, 26.0, 26.0, 25.0, 24.0, 23.0, 23.0, 24.0, 25.0, 36.0, 29.0, 27.0, 26.0, 26.0, 27.0, 25.0, 25.0, 25.0, 25.0, 26.0, 23.0, 25.0, 24.0, 25.0, 27.0, 25.0, 24.0, 24.0, 23.0, 24.0, 24.0, 23.5, 22.0, 22.0, 23.0, 23.0, 23.0, 22.0, 24.0, 41.0, 28.0, 26.0, 25.0, 24.0, 25.0, 24.0, 22.0, 22.0, 23.0, 23.0, 22.0, 21.0, 22.0, 23.0, 23.0, 21.0, 19.0, 20.0, 19.0, 20.0, 19.0, 20.0, 19.0, 19.0, 20.0, 19.0, 19.0, 20.0, 20.0, 25.0, 21.0, 21.0, 20.0, 20.0, 20.0, 21.0, 20.0, 21.0, 19.5, 19.0, 19.0, 19.0, 19.0, 19.0, 19.0, 18.0, 18.0, 17.0, 17.0, 18.0, 19.0, 19.0, 17.0, 18.0, 19.0, 19.0, 18.0, 18.0, 18.0, 26.0, 20.0, 19.0, 18.0, 18.0, 20.0, 17.0, 19.0, 17.0, 18.0, 19.0, 17.0, 17.0, 18.0, 17.0, 20.0, 18.0, 18.0, 17.0, 17.0, 18.0, 16.0, 17.0, 17.0, 17.0, 17.0, 17.0, 16.0, 18.0, 20.0, 23.0, 18.0, 17.0, 17.0, 16.0, 16.0, 15.0, 15.0, 15.0, 14.0, 14.0, 15.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 12.0, 14.0, 13.0, 14.0, 12.0, 13.0, 13.0, 13.0, 13.0, 13.0, 12.0, 20.0, 15.0, 14.0, 14.0, 12.0, 13.0, 13.0, 13.0, 12.0, 12.0, 12.0, 12.0, 12.0, 13.0, 12.0, 14.0, 12.0, 13.0, 12.0, 12.0, 13.0, 12.0, 12.0, 11.0, 12.0, 12.0, 11.0, 12.0, 12.0, 12.0, 33.0, 27.0, 24.0, 20.0, 19.0, 18.0, 17.0, 16.0, 15.0, 15.0, 16.0, 14.0, 14.0, 13.0, 13.0, 14.0, 13.0, 14.0, 14.0, 13.0, 14.0, 13.0, 13.0, 13.0, 12.0, 13.0, 13.0, 12.0, 13.0, 13.0, 24.0, 15.0, 16.0, 14.0, 14.0, 16.0, 15.5, 15.0, 14.0, 15.0, 15.0, 15.0, 14.0, 14.0, 14.0, 16.0, 14.0, 14.0, 14.0, 15.0, 15.0, 14.0, 14.0, 14.0, 14.0, 15.0, 15.0, 15.0, 14.0, 17.0, 26.0, 21.0, 19.0, 19.0, 19.0, 19.0, 20.0, 19.0, 19.0, 19.0, 20.0, 19.0, 19.0, 19.0, 19.0, 20.0, 20.0, 20.0, 19.0, 18.0, 19.0, 19.0, 20.0, 18.0, 19.0, 19.0, 20.0, 18.0, 19.0, 22.0, 47.0, 31.0, 30.0, 28.0, 28.0, 28.0, 27.0, 26.0, 28.0, 29.0, 31.0, 29.0, 30.0, 30.0, 32.0, 36.0, 27.0, 29.0, 29.0, 27.0, 30.0, 28.0, 27.0, 26.0, 28.0, 28.0, 28.0, 28.0, 28.0, 31.0, 38.0, 33.0, 31.0, 30.0, 29.0, 30.0, 29.0, 30.0, 29.0, 30.0, 33.0, 30.0, 30.0, 30.0, 31.0, 32.0, 32.0, 32.0, 31.0, 31.0, 33.0, 32.0, 31.0, 32.0, 32.0, 33.5, 32.0, 32.0, 34.0, 41.0, 99.0, 73.0, 76.0, 64.0, 64.0, 72.0, 72.0, 68.0, 63.0, 66.0, 70.0, 70.0, 62.0, 63.0, 63.0, 72.0, 66.0, 66.0, 65.0, 62.0, 65.0, 63.0, 59.0, 59.0, 62.0, 61.0, 62.0, 61.0, 60.0, 64.0, 82.0, 69.0, 67.0, 67.0, 62.0, 68.5, 65.0, 66.0, 64.0, 66.0, 66.0, 62.0, 65.0, 65.0, 61.0, 68.0, 64.0, 64.0, 65.0, 65.0, 69.0, 66.0, 62.0, 64.0, 64.0, 70.0, 65.0, 65.0, 67.0, 75.0, 167.0, 120.0, 111.0, 102.0, 100.0, 107.0, 105.0, 102.5, 96.0, 97.0, 101.5, 99.0, 95.0, 87.0, 89.0, 101.0, 94.0, 94.0, 93.0, 95.0, 100.0, 96.0, 96.0, 94.0, 101.0, 119.0, 134.0, 140.0, 149.0, 211.0, 219.0, 160.0, 127.0, 115.0, 112.0, 108.0, 101.0, 96.0, 90.0, 91.0, 94.0, 90.0, 86.0, 85.0, 89.0, 94.0, 91.0, 83.0, 82.0, 81.0, 86.0, 82.0, 82.0, 77.0, 79.0, 83.0, 84.0, 77.0, 76.0, 83.0, 132.5, 108.0, 104.0, 97.0, 99.0, 97.0, 94.0, 90.0, 85.0, 87.0, 92.0, 86.0, 86.0, 84.0, 83.0, 92.0, 86.0, 86.0, 86.0, 83.0, 86.0, 83.0, 78.0, 77.0, 81.0, 81.0, 76.0, 78.0, 77.0, 78.0, 98.0, 91.0, 84.0, 83.0, 81.0, 84.0, 81.0, 81.0, 78.0, 76.0, 82.0, 79.0, 78.0, 74.0, 77.0, 81.0, 78.0, 78.0, 80.0, 79.0, 85.0, 76.0, 76.5, 75.0, 76.0, 79.0, 75.0, 73.0, 70.0, 73.0, 109.0, 93.0, 91.0, 85.0, 85.0, 88.0, 82.0, 81.0, 79.0, 76.0, 82.0, 78.0, 80.0, 75.0, 77.0, 81.0, 79.0, 76.0, 78.0, 74.0, 81.0, 78.0, 74.0, 72.0, 73.0, 77.0, 74.0, 75.0, 71.0, 73.0, 95.0, 83.0, 83.0, 81.0, 79.0, 83.0, 79.0, 76.0, 75.0, 74.0, 84.0, 74.0, 75.5, 75.0, 76.0, 86.0, 79.0, 76.0, 73.0, 74.0, 80.0, 77.0, 75.5, 70.0, 73.0, 76.0, 73.0, 73.0, 70.0, 80.0, 112.0, 88.0, 89.0, 86.0, 87.0, 89.0, 87.0, 85.0, 85.0, 82.0, 90.0, 88.0, 87.0, 87.0, 86.0, 92.0, 87.0, 88.0, 86.0, 88.0, 90.0, 93.0, 89.0, 85.0, 90.0, 94.0, 91.0, 84.5, 86.0, 86.0, 110.0, 104.0, 102.0, 94.5, 101.0, 106.0, 100.0, 96.0, 89.0, 92.0, 99.0, 95.0, 95.0, 94.0, 95.0, 108.0, 104.0, 98.0, 110.0, 106.0, 117.0, 112.0, 108.5, 107.0, 105.0, 109.0, 108.0, 110.0, 103.0, 112.0, 187.0, 152.0, 138.0, 137.0, 135.5, 146.0, 136.0, 129.0, 130.0, 134.0, 141.0, 133.0, 137.0, 131.0, 137.0, 153.0, 147.0, 140.0, 142.0, 150.0, 174.0, 157.0, 149.0, 145.0, 151.0, 160.0, 147.0, 136.0, 132.0, 138.0, 254.0, 229.0, 222.0, 212.0, 207.0, 230.0, 210.0, 206.0, 201.0, 194.0, 209.0, 199.0, 201.0, 202.0, 200.0, 225.0, 220.0, 201.0, 202.0, 212.0, 225.0, 210.0, 210.0, 200.0, 210.0, 231.0, 231.0, 218.0, 225.0, 321.0, 1018.0, 588.0, 491.0, 456.0, 441.0, 477.0, 427.0, 411.0, 375.0, 377.0, 422.0, 368.0, 359.0, 342.0, 342.0, 400.0, 373.0, 355.0, 358.0, 363.0, 387.0, 357.0, 350.0, 336.0, 328.0, 348.0, 316.0, 301.0, 305.0, 313.0, 599.0, 535.0, 504.0, 498.5, 485.0, 536.0, 505.0, 468.5, 455.0, 470.0, 516.0, 464.0, 452.5, 436.0, 430.0, 519.0, 473.0, 451.0, 433.0, 436.0, 495.0, 456.0, 456.0, 431.0, 437.0, 467.0, 424.0, 400.0, 372.0, 452.0, 1067.0, 804.0, 715.0, 667.5, 632.0, 689.0, 624.0, 575.5, 569.0, 555.0, 605.0, 546.5, 522.0, 495.0, 511.0, 603.5, 532.0, 512.5, 512.0, 491.0, 543.0, 499.0, 472.0, 451.0, 463.0, 500.0, 477.0, 457.0, 435.0, 461.0, 773.0, 705.5, 680.0, 644.0, 639.0, 689.0, 668.0, 620.5, 581.0, 584.0, 667.0, 597.5, 590.5, 568.0, 559.0, 668.0, 605.0, 577.0, 571.0, 566.0, 610.0, 585.5, 575.0, 537.0, 548.0, 586.0, 532.0, 520.0, 491.0, 519.0, 778.0, 703.0, 648.0, 607.0, 586.0, 633.0, 578.0, 552.0, 534.0, 523.0, 610.0, 566.5, 534.0, 525.0, 516.0, 595.0, 552.0, 522.0, 516.5, 518.0, 560.0, 531.0, 513.0, 498.0, 530.0, 578.0, 550.0, 545.0, 602.0, 799.0, 918.0, 644.5, 585.0, 548.0, 525.0, 569.0, 523.0, 496.0, 489.0, 470.0, 526.0, 480.0, 470.0, 455.0, 469.5, 545.0, 466.0, 440.0, 424.0, 440.0, 466.0, 434.0, 415.0, 404.5, 412.0, 449.0, 430.0, 416.0, 408.0, 443.0, 586.0, 495.5, 445.0, 435.0, 434.0, 461.0, 437.0, 416.0, 395.0, 404.0, 437.0, 400.0, 387.0, 381.0, 373.5, 427.0, 404.0, 375.0, 394.0, 380.0, 418.0, 397.0, 386.0, 369.0, 384.5, 411.0, 383.0, 385.0, 420.0, 511.0, 555.0, 415.0, 373.0, 358.0, 359.5, 362.0, 348.5, 339.0, 321.0, 324.5, 348.0, 329.0, 316.0, 315.0, 312.0, 356.0, 321.0, 310.0, 301.0, 310.0, 329.0, 319.0, 305.0, 302.0, 296.0, 315.0, 293.0, 289.0, 289.0, 297.5, 407.0, 342.0, 321.0, 312.0, 304.0, 335.0, 315.0, 302.0, 297.0, 293.5, 308.0, 285.5, 290.0, 283.0, 289.0, 326.0, 300.5, 294.0, 285.0, 281.0, 310.0, 291.0, 289.0, 277.0, 281.0, 306.0, 292.0, 280.5, 279.0, 292.5, 365.0, 316.0, 303.0, 290.0, 287.0, 319.0, 298.0, 287.0, 274.0, 287.0, 303.5, 282.0, 275.0, 271.0, 273.0, 312.0, 289.0, 280.0, 276.0, 274.0, 299.0, 295.0, 281.0, 280.0, 285.0, 306.0, 299.0, 288.0, 295.0, 319.0, 439.0, 379.0, 378.0, 368.0, 353.0, 396.0, 384.0, 363.0, 356.0, 366.0, 406.0, 389.0, 388.5, 378.5, 396.0, 477.0, 460.5, 436.0, 424.0, 443.5, 524.5, 506.0, 503.0, 508.0, 571.5, 687.5, 739.5, 1058.0, 1998.0, 1973.0, 916.5, 459.5, 358.5, 310.0, 274.0, 262.0, 239.0, 225.0, 212.5, 203.0, 214.5, 191.0, 186.0, 176.0, 182.5, 185.0, 170.0, 163.0, 161.0, 162.5, 167.0, 156.0, 156.5, 151.0, 153.0, 157.0, 151.0, 150.0, 140.0, 164.0, 206.0, 164.0, 159.0, 157.5, 156.0, 156.0, 150.0, 148.0, 144.0, 150.5, 161.0, 154.0, 148.0, 152.0, 260.5, 267.0, 168.0, 161.0, 153.0, 150.0, 147.0, 147.0, 148.0, 144.0, 145.0, 148.0, 151.5, 147.0, 145.0, 150.0, 174.0, 142.0, 134.0, 120.0, 113.0, 110.0, 105.0, 101.0, 96.0, 94.0, 98.0, 93.0, 89.0, 86.0, 89.0, 100.0, 121.0, 82.0, 79.0, 78.0, 100.0, 80.0, 74.0, 72.5, 77.0, 91.0, 74.0, 80.0, 86.0, 126.0, 108.0, 63.0, 52.0, 48.0, 46.0, 48.0, 46.0, 44.0, 43.0, 43.0, 45.0, 42.0, 42.0, 42.0, 53.0, 52.0, 38.0, 37.0, 34.0, 33.0, 37.0, 35.0, 33.0, 33.0, 33.0, 42.0, 35.0, 34.0, 34.0, 39.0, 75.0, 46.0, 41.0, 39.0, 38.0, 40.0, 36.0, 36.0, 35.0, 38.0, 44.0, 35.0, 35.0, 34.0, 41.0, 63.0, 44.0, 37.0, 33.0, 40.0, 70.0, 37.0, 34.0, 34.0, 41.0, 66.0, 43.0, 40.0, 53.0, 87.0, 43.0, 27.0, 21.0, 22.0, 20.0, 22.0, 19.0, 18.0, 18.0, 19.0, 23.0, 21.0, 20.0, 23.0, 35.0, 23.0, 23.5, 21.0, 23.0, 21.0, 22.0, 20.0, 21.0, 20.0, 20.0, 29.0, 21.0, 20.0, 21.0, 27.0, 69.5, 33.0, 31.5, 30.0, 28.0, 28.0, 25.0, 26.0, 26.0, 28.0, 29.0, 23.0, 22.0, 24.0, 28.0, 23.0, 25.0, 26.0, 25.0, 29.0, 55.0, 27.0, 24.0, 25.0, 29.0, 55.0, 32.0, 27.0, 38.0, 54.0, 77.0, 28.5, 23.0, 19.0, 18.0, 17.0, 15.0, 15.0, 13.0, 13.0, 14.0, 12.0, 14.0, 13.5, 17.0, 12.0, 11.0, 11.0, 10.0, 10.0, 11.0, 11.0, 10.0, 9.5, 10.0, 10.0, 9.0, 9.0, 9.0, 9.0, 12.0, 10.0, 10.0, 10.0, 9.0, 9.0, 10.0, 10.0, 9.0, 9.0, 10.0, 9.0, 9.0, 9.0, 8.0, 8.0, 9.0, 9.0, 9.0, 8.0, 9.0, 9.0, 9.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 9.0, 30.0, 18.0, 15.0, 14.0, 14.0, 14.0, 13.0, 12.5, 12.0, 11.0, 11.0, 10.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 8.0, 9.0, 9.0, 9.0, 9.0, 11.0, 10.0, 9.0, 9.0, 9.0, 10.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 12.0, 11.0, 10.0, 10.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 10.0, 10.0, 13.0]
which if we plot we can see (qualitatively) a maximal region between roughly 750 and 1100.
We can see this maximal region more clearly if we smooth the data:
pd.Series(data).ewm(span=100).mean().plot()
My question is, what techniques/algorithms can be used to identify the interval say (800, 1200)? I have many such datasets which have different shapes, but all include 1 or 2 maximal "regions".
Any ideas? Thanks
Here's the mountain climber solution to the problem I mentioned in my comment. I saved the data you posted to a numpy file: https://drive.google.com/file/d/192jp5LvEE0Dc8QVMVmzzuHSehl2_bBLF/view?usp=sharing
Graph after mean filtering and mountain climbing
Bounds after thresholding based on the value at the start of the rise.
import numpy as np
import matplotlib.pyplot as plt
# returns direction of gradient
# 1 if positive, -1 if negative, 0 if flat
def getDirection(one, two):
dx = two - one;
if dx == 0:
return 0;
if dx > 0:
return 1;
return -1;
# detects and returns peaks and valleys
def mountainClimber(vals, minClimb):
# init trackers
last_valley = vals[0];
last_peak = vals[0];
last_val = vals[0];
last_dir = getDirection(vals[0], vals[1]);
# get climbing
peak_valley = []; # index, height, climb (positive for peaks, negative for valleys)
for a in range(1, len(vals)):
# get current direction
sign = getDirection(last_val, vals[a]);
last_val = vals[a];
# if not equal, check gradient
if sign != 0:
if sign != last_dir:
# change in gradient, record peak or valley
# peak
if last_dir > 0:
last_peak = vals[a];
climb = last_peak - last_valley;
climb = round(climb, 2);
peak_valley.append([a, vals[a], climb]);
else:
# valley
last_valley = vals[a];
climb = last_valley - last_peak;
climb = round(climb, 2);
peak_valley.append([a, vals[a], climb]);
# change direction
last_dir = sign;
# filter out very small climbs
filtered_pv = [];
for dot in peak_valley:
if abs(dot[2]) > minClimb:
filtered_pv.append(dot);
return filtered_pv;
# run an mean filter over the graph values
def meanFilter(vals, size):
fil = [];
filtered_vals = [];
for val in vals:
fil.append(val);
# check if full
if len(fil) >= size:
# pop front
fil = fil[1:];
filtered_vals.append(sum(fil) / size);
else:
# pad to maintain index positions
filtered_vals.append(0);
return filtered_vals;
# load from file
data = np.load("data.npy");
# filter and round values
mean_filter_size = 150;
filtered_vals = meanFilter(data, mean_filter_size);
# get peaks and valleys
pv = mountainClimber(filtered_vals, 0);
# filter for the largest climb
biggest_climb = -1;
top_index = None;
for pv_index, feature in enumerate(pv):
# unpack
_, _, climb = feature;
# check climb
if climb > biggest_climb:
biggest_climb = climb;
top_index = pv_index;
# pull out the threshold
start = pv[top_index - 1][0];
threshold = pv[top_index - 1][1];
# look through and find the first spot where the graph drops below threshold
end = None;
for index in range(start + 1, len(data)):
if data[index] < threshold:
end = index;
break;
# draw the bounding lines
markers_x = [start, end];
markers_y = [data[start], data[end]];
# draw plot
x = [a for a in range(len(data))];
fig = plt.figure();
ax = plt.axes();
ax.plot(x, data);
ax.plot(markers_x, markers_y, 'or');
plt.show();
My TopoJSON object contains 3 polygonal sub-objects of which the first D2P1 appears with the geometry correctly drawn on the OSM map, but the other 2 polygons D2P2 and D2P3 are drawn distorted on the map turning into projected lines instead of their! correct geometry.
Could you help me to write my code correctly so that my 3 polygons appear correctly configured?
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io#master/en/v6.
3.1/build/ol.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io#master/en/v6
.3.1/css/ol.css" type="text/css">
<style>
/*estilo de la caja del mapa*/
#map {
width: 100%;
height: 700px;
box-shadow: 5px 5px 5px #888;
}
</style>
<style>
/*estilo de los controles del mapa*/
.ol-mouse-position {
/*estilo del control de longitud y latitud */
font-size: 12px;
font-family: Arial Black;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var osm = new ol.layer.Tile({ // capa osm (Open Street Maps)
source: new ol.source.OSM()
});
// OBJETO TopoJSON
var Y = {
"type": "Topology",
"arcs": [
[
[711, 1839],
[-37, -99],
[-3, -8],
[-2, -4],
[-3, -4],
[-2, -3],
[-1, -1],
[-2, -1],
[-3, -3],
[-2, -1],
[-4, -2],
[-1, 0],
[-3, -1],
[-24, 1],
[-12, -3],
[-10, -15],
[-1, -3],
[-5, -13],
[-2, -23],
[-1, -94],
[275, -220],
[17, -31],
[34, -52],
[117, -112],
[19, -19],
[30, -142]
],
[
[1085, 986],
[-5, -9],
[0, 0],
[-30, -40],
[-47, -48],
[-18, -16],
[-21, -16],
[-45, -61],
[-16, -16],
[-4, -4],
[-101, -125],
[-28, -6],
[-5, -7],
[-3, -2],
[-3, -1],
[-7, -16],
[-573, 431],
[-1, 1],
[-12, 5],
[-9, 3],
[-157, 6],
[16, 868],
[14, 15],
[82, 49],
[599, -158]
],
[
[711, 1839],
[315, -82],
[459, -119],
[-3, -4],
[-143, -167],
[75, -84],
[-12, -10],
[-39, -51],
[-3, -3],
[-15, -16],
[-76, -26],
[-133, -211],
[-28, -44],
[-23, -36]
],
[
[2354, 410],
[-76, -313],
[-220, 43],
[-37, -140],
[-11, 11],
[-129, 128],
[-17, 17],
[-6, 5],
[-5, 2],
[-7, 3],
[-8, 2],
[-15, 4],
[-173, 40],
[-169, 39],
[-2, 6],
[3, 33],
[-239, 651],
[-21, 32],
[-86, 93],
[133, 211],
[76, 26],
[15, 16],
[3, 3],
[39, 51],
[12, 10],
[-75, 84],
[146, 171],
[2, 1],
[16, 3],
[11, 2],
[9, 1],
[16, 2],
[20, 3],
[20, 1],
[16, 2],
[21, -2],
[14, -2],
[20, -3],
[18, -4],
[21, -8],
[24, -10],
[15, -9],
[23, -14],
[39, -28],
[32, -27],
[20, -14],
[32, -18],
[22, -10],
[23, -6],
[35, -4],
[33, -5],
[41, -1],
[74, -8],
[44, -15],
[73, -32],
[101, -41],
[169, -77],
[118, -51],
[74, -35],
[12, -5],
[-15, -66],
[-41, -179],
[-69, -252],
[-35, -26],
[-3, -9],
[-7, -15],
[-14, -48],
[-4, -57],
[-7, -16],
[-39, -41],
[-14, -22],
[-21, -44],
[-23, -3],
[-15, -1],
[-9, -2],
[-8, -6],
[-10, -16],
[-5, -11],
[0, 0]
]
],
"transform": {
"scale": [0.00001991525380089962, 0.000012987212987305721],
"translate": [-98.20093192354561, 19.06017018766488]
},
"objects": {
"D2P1": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[0, 1]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 1 P.MARIA AUXILIO DE LOS CRISTIANOS",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
},
"D2P2": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[-1, 2]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 2 P. NUESTRA SEÑORA DE LA CANDELARIA",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
},
"D2P3": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[3]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 3 P. SEÑOR DE LAS MARAVILLAS",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
}
}
};
/* source*/
var sourceD2P1 = new ol.source.Vector({
features: (new ol.format.TopoJSON({
layers: ['D2P1']
})).readFeatures(Y, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}),
});
var sourceD2P2 = new ol.source.Vector({
features: (new ol.format.TopoJSON({
layers: ['D2P2']
})).readFeatures(Y, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}),
});
var sourceD2P3 = new ol.source.Vector({
features: (new ol.format.TopoJSON({
layers: ['D2P3']
})).readFeatures(Y, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}),
});
/*LAYER.VECTOR*/
var vectorD2P1 = new ol.layer.Vector({ // ----D2P1
source: sourceD2P1,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'green',
}),
stroke: new ol.style.Stroke({
color: 'green',
width: 1
})
})
});
var vectorD2P2 = new ol.layer.Vector({ // ----D2P2
source: sourceD2P2,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'red',
}),
stroke: new ol.style.Stroke({
color: 'red',
width: 1
})
})
});
var vectorD2P3 = new ol.layer.Vector({ // ----D2P3
source: sourceD2P3,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'blue',
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
})
})
});
var controls = ol.control.defaults().extend([
new ol.control.ScaleLine(), /*control del mapita lateral*/
new ol.control.Attribution(), /*control del letrero de Open Street Maps*/
new ol.control.MousePosition({ /*control de LONGITUD Y LATITUD en donde se coloque el mause*/
coordinateFormat: ol.coordinate.createStringXY(4),
projection: 'EPSG:4326'
}),
new ol.control.OverviewMap({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
]
}),
/*new ol.control.ZoomSlider(),*/
new ol.control.FullScreen() /*control de expancon u cerrado del mapa*/
]);
var Mivista = new ol.View({
center: ol.proj.fromLonLat([-98.2172, 19.03464]),
zoom: 12
}) //-98.197, 19.0433 puebla
var layers = [osm,
vectorD2P1, vectorD2P2, vectorD2P3,
];
// Creacion del mapa con las 3 capas
var map = new ol.Map({
/*target------*/
target: 'map',
/*layers------*/
layers: layers,
controls: controls,
/*view--------*/
view: Mivista,
});
Mivista.setRotation(-.4999) // Rota el plano 27 grados
</script>
</body>
</html>
I LEAVE YOU THE CODE THAT ANSWERS MY QUESTION, I HOPE IT WILL BE VERY USEFUL
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io#master/en/v6.
3.1/build/ol.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io#master/en/v6
.3.1/css/ol.css" type="text/css">
<style>
/*estilo de la caja del mapa*/
#map {
width: 100%;
height: 1000px;
box-shadow: 5px 5px 5px #888;
}
</style>
<style>
/*estilo de los controles del mapa*/
.ol-mouse-position {
/*estilo del control de longitud y latitud */
font-size: 12px;
font-family: Arial Black;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var osm = new ol.layer.Tile({ // capa osm (Open Street Maps)
source: new ol.source.OSM()
});
// OBJECTO_1 TopoJSON
var geojsonObjectochentaPARROQUIAS = {
// OBJETO TopoJSON
"type": "Topology",
"arcs": [
[
[711, 1839],
[-37, -99],
[-3, -8],
[-2, -4],
[-3, -4],
[-2, -3],
[-1, -1],
[-2, -1],
[-3, -3],
[-2, -1],
[-4, -2],
[-1, 0],
[-3, -1],
[-24, 1],
[-12, -3],
[-10, -15],
[-1, -3],
[-5, -13],
[-2, -23],
[-1, -94],
[275, -220],
[17, -31],
[34, -52],
[117, -112],
[19, -19],
[30, -142]
],
[
[1085, 986],
[-5, -9],
[0, 0],
[-30, -40],
[-47, -48],
[-18, -16],
[-21, -16],
[-45, -61],
[-16, -16],
[-4, -4],
[-101, -125],
[-28, -6],
[-5, -7],
[-3, -2],
[-3, -1],
[-7, -16],
[-573, 431],
[-1, 1],
[-12, 5],
[-9, 3],
[-157, 6],
[16, 868],
[14, 15],
[82, 49],
[599, -158]
],
[
[711, 1839],
[315, -82],
[459, -119],
[-3, -4],
[-143, -167],
[75, -84],
[-12, -10],
[-39, -51],
[-3, -3],
[-15, -16],
[-76, -26],
[-133, -211],
[-28, -44],
[-23, -36]
],
[
[2354, 410],
[-76, -313],
[-220, 43],
[-37, -140],
[-11, 11],
[-129, 128],
[-17, 17],
[-6, 5],
[-5, 2],
[-7, 3],
[-8, 2],
[-15, 4],
[-173, 40],
[-169, 39],
[-2, 6],
[3, 33],
[-239, 651],
[-21, 32],
[-86, 93],
[133, 211],
[76, 26],
[15, 16],
[3, 3],
[39, 51],
[12, 10],
[-75, 84],
[146, 171],
[2, 1],
[16, 3],
[11, 2],
[9, 1],
[16, 2],
[20, 3],
[20, 1],
[16, 2],
[21, -2],
[14, -2],
[20, -3],
[18, -4],
[21, -8],
[24, -10],
[15, -9],
[23, -14],
[39, -28],
[32, -27],
[20, -14],
[32, -18],
[22, -10],
[23, -6],
[35, -4],
[33, -5],
[41, -1],
[74, -8],
[44, -15],
[73, -32],
[101, -41],
[169, -77],
[118, -51],
[74, -35],
[12, -5],
[-15, -66],
[-41, -179],
[-69, -252],
[-35, -26],
[-3, -9],
[-7, -15],
[-14, -48],
[-4, -57],
[-7, -16],
[-39, -41],
[-14, -22],
[-21, -44],
[-23, -3],
[-15, -1],
[-9, -2],
[-8, -6],
[-10, -16],
[-5, -11],
[0, 0]
]
],
"transform": {
"scale": [0.00001991525380089962, 0.000012987212987305721],
"translate": [-98.20093192354561, 19.06017018766488]
},
"objects": {
"D2P1": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[0, 1]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 1 P.MARIA AUXILIO DE LOS CRISTIANOS",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
},
"D2P2": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[-1, 2]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 2 P. NUESTRA SEÑORA DE LA CANDELARIA",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
},
"D2P3": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[3]
],
"type": "Polygon",
"properties": {
"Name": "(STA. MARÍA) 3 P. SEÑOR DE LAS MARAVILLAS",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
}
}
};
// OBJECTO_2 TopoJSON
var geojsonObjectXXX = { // -------------------------------------------------ObjectXXX-----Municipio_TopoJSON
"type": "Topology",
"arcs": [
[
[3698, 68],
[-126, 23],
[-54, 8],
[-370, -99],
[-112, 35],
[-249, 34],
[-133, 44],
[-62, 66],
[-35, 73],
[29, 117],
[-38, 91],
[-95, 135],
[-58, 226],
[-38, 29],
[-24, 82],
[-102, 79],
[-64, 94],
[-91, 38],
[-98, 4],
[-104, -18],
[-77, -53],
[-95, -37],
[-37, -47],
[-139, -59],
[-55, -59],
[-105, -57],
[-62, -10],
[-93, 35],
[-536, -78],
[-105, 19],
[-76, 98],
[-39, 16],
[-160, 3],
[14, 30],
[59, 50],
[63, 87],
[112, 135],
[23, 71],
[-49, 67],
[-52, 37],
[-19, 0],
[-20, -17],
[-66, 9],
[-79, -8],
[-62, -14],
[-82, 14],
[-43, 3],
[-62, 63],
[-32, 81],
[9, 39],
[41, 52],
[30, 18],
[5, 40],
[13, 25],
[25, 3],
[46, -9],
[46, -1],
[38, 9],
[33, 28],
[-10, 36],
[-23, 53],
[-8, 30],
[22, 45],
[35, 110],
[2, 15],
[25, 173],
[1, 79],
[1, 142],
[-5, 202],
[28, 10],
[58, -2],
[54, 4],
[42, 16],
[13, 41],
[-94, 114],
[-39, 34],
[-6, 11],
[-8, 15],
[9, 43],
[-35, 77],
[5, 103],
[-4, 66],
[-39, 64],
[-28, 20],
[-66, 49],
[-58, 63],
[68, 31],
[18, 35],
[0, 61],
[3, 61],
[32, 55],
[38, 29],
[-80, 137],
[87, 24],
[35, 47],
[52, 23],
[96, 28],
[39, -76],
[44, -33],
[47, 42],
[30, 22],
[111, -8],
[44, 17],
[19, 62],
[28, 17],
[90, -2],
[55, 76],
[59, 91],
[20, 68],
[20, 69],
[34, 48],
[115, 70],
[27, 46],
[46, -1],
[78, -2],
[75, 71],
[92, -18],
[41, 21],
[2, 2],
[54, 90],
[68, 18],
[3, 4],
[38, 63],
[15, 45],
[51, 28],
[35, 62],
[5, 46],
[-68, 115],
[-66, 37],
[-54, 31],
[-78, 33],
[-23, 33],
[-12, 19],
[-19, -18],
[41, -92],
[-123, 10],
[-240, 19],
[39, 16],
[-23, 7],
[-98, 33],
[-27, 12],
[-37, 17],
[-144, -129],
[-16, 101],
[-113, 53],
[-45, 71],
[-186, 20],
[48, 138],
[53, -5],
[156, 112],
[-61, 124],
[-86, 32],
[52, 150],
[47, 145],
[12, 39],
[18, 39],
[2, 4],
[22, 77],
[-53, 28],
[-39, 24],
[110, 66],
[25, 15],
[14, 35],
[18, 139],
[62, -7],
[58, 85],
[91, -52],
[78, -12],
[106, -17],
[22, 86],
[5, 22],
[10, 42],
[57, 31],
[6, 36],
[-17, 37],
[-11, 8],
[-11, -5],
[1, 9],
[-29, 54],
[-4, 62],
[-3, 4],
[-18, 24],
[86, 51],
[27, -26],
[30, 34],
[15, 38],
[93, -57],
[27, 15],
[22, 15],
[8, 14],
[-5, 32],
[-15, 36],
[6, 28],
[24, 27],
[7, 42],
[62, 57],
[1, 16],
[-79, 55],
[1, 14],
[42, 25],
[21, 1],
[24, 20],
[5, 69],
[-11, 22],
[-24, 23],
[0, 13],
[4, 38],
[11, 8],
[6, 21],
[-12, 12],
[0, 16],
[15, 19],
[6, 19],
[4, 91],
[9, 10],
[-7, 19],
[14, 10],
[17, 2],
[17, -8],
[44, -7],
[23, 9],
[15, 11],
[12, 28],
[-12, 35],
[9, 8],
[-6, 101],
[10, -12],
[25, -36],
[31, 34],
[21, -30],
[3, -16],
[60, 2],
[-5, 12],
[40, -12],
[40, -17],
[37, -19],
[48, -8],
[15, 3],
[32, -3],
[29, -9],
[27, -2],
[48, 4],
[26, 2],
[29, 7],
[25, 4],
[23, 11],
[15, 10],
[22, 3],
[-1, -8],
[16, -15],
[28, -17],
[11, -10],
[3, -7],
[-3, -8],
[-18, -21],
[-3, -14],
[1, -12],
[12, -23],
[3, -10],
[-3, -11],
[-14, -11],
[-10, -14],
[-4, -20],
[4, -13],
[7, -14],
[6, -12],
[8, -24],
[15, -68],
[-1, -106],
[-5, -23],
[-2, -64],
[-5, -17],
[-16, -36],
[17, -9],
[25, -4],
[40, 4],
[40, 9],
[28, 16],
[20, 19],
[43, -1],
[16, 10],
[16, -6],
[23, -22],
[77, -31],
[123, -53],
[83, -43],
[22, -7],
[125, -52],
[210, -80],
[174, -74],
[45, -19],
[44, -14],
[61, 12],
[14, 5],
[12, 7],
[4, 5],
[9, 4],
[2, 3],
[10, 3],
[38, 27],
[3, 3],
[3, 5],
[2, 5],
[0, 4],
[5, 8],
[27, -18],
[18, -12],
[31, 42],
[39, 35],
[58, 34],
[129, 56],
[53, 30],
[34, 21],
[29, 21],
[63, 48],
[33, 14],
[20, 6],
[19, 1],
[24, 6],
[15, 6],
[19, 13],
[213, 202],
[161, 201],
[31, 79],
[22, 52],
[93, 97],
[86, 64],
[37, 63],
[112, 50],
[-11, 11],
[46, 16],
[22, 16],
[24, 28],
[12, 4],
[70, 27],
[15, 10],
[19, 7],
[16, 9],
[7, 15],
[2, 13],
[3, 9],
[7, 8],
[20, 16],
[13, 11],
[15, 9],
[11, 19],
[24, 10],
[13, 9],
[9, 1],
[11, 5],
[11, 1],
[18, -2],
[22, -2],
[44, 0],
[38, 32],
[6, 56],
[-7, 76],
[30, 76],
[93, 127],
[209, 2],
[33, -1],
[118, -5],
[120, 116],
[203, 130],
[178, 202],
[177, 151],
[141, 43],
[124, 102],
[137, 213],
[133, 176],
[127, 158],
[12, 217],
[51, 110],
[94, -27],
[65, -115],
[6, -171],
[3, -22],
[241, -231],
[-135, -147],
[-47, 16],
[-6, -79],
[-126, -184],
[-13, -90],
[-71, 70],
[-52, -46],
[1, -114],
[35, -117],
[-16, -246],
[3, -183],
[-1, -35],
[-50, -141],
[1, -113],
[-46, -302],
[57, -66],
[136, 198],
[86, 8],
[-24, -126],
[-65, -35],
[-13, -69],
[-13, -72],
[-34, -43],
[-34, -102],
[-87, 11],
[-37, -13],
[-81, -95],
[-61, -33],
[-89, -50],
[16, -78],
[-18, -75],
[-67, -46],
[-130, -61],
[-22, -37],
[43, -182],
[-22, -105],
[-42, -20],
[-27, -5],
[-24, -8],
[-37, -65],
[-65, -47],
[-70, -17],
[-103, -52],
[-74, -89],
[-6, -101],
[-36, -43],
[-46, -146],
[-97, -161],
[-22, -93],
[-31, -21],
[-46, -165],
[-54, -190],
[-4, -40],
[77, -92],
[28, -57],
[-1, 0],
[-315, 73],
[-74, 2],
[-138, 4],
[-162, -25],
[-132, -20],
[-157, -3],
[-65, -52],
[-24, -160],
[-42, -30],
[-7, -15],
[2, -29],
[21, 6],
[23, -32],
[-104, 0],
[-12, -2],
[-254, -4],
[1, -12],
[-29, 0],
[0, -25],
[-42, 4],
[-93, 9],
[2, -7],
[-7, 0],
[-27, -1],
[-23, -13],
[0, -16],
[48, -67],
[40, -5],
[38, -6],
[44, -6],
[40, -31],
[11, -8],
[39, -30],
[32, -26],
[93, -72],
[-26, -120],
[-159, -128],
[-12, -10],
[-23, -139],
[-24, -149],
[-118, -199],
[44, -84],
[-23, -60],
[-28, 22],
[-17, -29],
[-75, -43],
[-73, -9],
[-4, -18],
[-45, -53],
[51, -150],
[70, -150],
[19, -90],
[-65, -91],
[-21, -30],
[3, -345],
[-10, -48],
[14, -49],
[-29, -32],
[13, -18],
[34, -47],
[-2, -32],
[-3, -41],
[85, -25],
[62, -46],
[70, -52],
[80, -33],
[193, -65],
[80, -66],
[55, -138],
[-38, -73],
[23, -56],
[278, -196],
[92, -53],
[117, -37],
[118, -210],
[-120, -1],
[-185, -48],
[-77, 56],
[-285, -61],
[-28, -169],
[-205, -26],
[67, 172],
[-131, 34],
[-3, 73],
[-174, 7],
[-16, -66],
[-50, -23],
[-54, 33],
[-208, -45],
[-43, -70],
[-42, -3],
[-70, -39],
[-162, -442],
[-7, -315],
[-153, -388],
[-11, -185],
[-98, -58]
]
],
"transform": {
"scale": [3.750052683335661, 4.395371608583082],
"translate": [-10941343.283091985, 2137380.706460472]
},
"objects": {
"municipioDePuebla": {
"type": "GeometryCollection",
"geometries": [{
"arcs": [
[0]
],
"type": "Polygon",
"properties": {
"Name": "MUNICIPIO DE PUEBLA",
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"snippet": ""
}
}]
}
}
}; // Municipio_TopoJSON
/* ol.format.TopoJSON------------------------------------------------------------------------------------------------------------------*/
var sourceOchentaPARROQUIAS = new ol.source.Vector({
features: (new ol.format.TopoJSON({
layers: ['D2P1', 'D2P2', 'D2P3']
})).readFeatures(geojsonObjectochentaPARROQUIAS, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
})
});
var sourceMunicipio = new ol.source.Vector({
features: (new ol.format.TopoJSON()).readFeatures(geojsonObjectXXX)
});
/* ol.layer.Vector-----------------------------------------------------------------------------------------------------------------------*/
function generateRandomColor(seed) {
let r = Math.floor(Math.random() * 255)
let g = Math.floor(Math.random() * 255)
let b = Math.floor(Math.random() * 255)
return `rgba(${r}, ${g}, ${b}, 0.3)`
}
let features = sourceOchentaPARROQUIAS.getFeatures()
let colors = {}
features.forEach((feature, i) => {
let geom = feature.getGeometry()
colors[geom.ol_uid] = generateRandomColor(geom.ol_uid)
})
function vectorStyleFunction(feature) {
let geom = feature.getGeometry()
let id = geom.ol_uid
let style = new ol.style.Style({
fill: new ol.style.Fill({
color: colors[id]
}),
stroke: new ol.style.Stroke({
color: /*'rgba(9, 87, 140, 1)',*/ 'blue',
width: 1
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
fill: new ol.style.Fill({
color: '#000',
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 3,
}),
}),
})
// style.getText().setText(geom.ol_uid);
return style
}
var vectorLayerOchentaPARROQUIAS = new ol.layer.Vector({ // ----82 POLIGONOS
source: sourceOchentaPARROQUIAS,
style: vectorStyleFunction
});
var vectorLayerMunicipioDePuebla = new ol.layer.Vector({ // ----1 POLIGONO
source: sourceMunicipio,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.00)'
}),
stroke: new ol.style.Stroke({
color: '#09a7ee',
width: 2
}),
})
});
/* CONTROLES-----------------------------------------------------------------------------------------------------------------------*/
var controls = ol.control.defaults().extend([
new ol.control.ScaleLine(), /*control del mapita lateral*/
new ol.control.Attribution(), /*control del letrero de Open Street Maps*/
new ol.control.MousePosition({ /*control de LONGITUD Y LATITUD en donde se coloque el mause*/
coordinateFormat: ol.coordinate.createStringXY(4),
projection: 'EPSG:4326'
}),
new ol.control.OverviewMap({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
]
}),
/*new ol.control.ZoomSlider(),*/
new ol.control.FullScreen() /*control de expancon u cerrado del mapa*/
]);
// Creacion del mapa con las TRES capas
var Mivista = new ol.View({
center: ol.proj.fromLonLat([-98.2172, 19.0150]),
zoom: 12
}) //-98.197, 19.0433 puebla
// pedida de capas
/*LAYERS*/
var layers = [osm, vectorLayerOchentaPARROQUIAS, vectorLayerMunicipioDePuebla];
var map = new ol.Map({
/*target------*/
target: 'map',
layers: layers,
controls: controls,
/*view--------*/
view: Mivista,
});
Mivista.setRotation(-.4999) // Rota el plano 27 grados en sentido contrario de las manecillas del reloj
</script>
</body>
</html>