colorFactor ile Renk Paleti Oluşturma
Şu ana kadar haritamızın stilini özelleştirmek için rengi sadece doğrudan kullandık. colorFactor() ile bir faktör değişkeninin düzeylerine renkleri eşleyen bir renk paleti oluşturabiliriz.
pal <-
colorFactor(palette = c("blue", "red", "green"),
levels = c("Public", "Private", "For-Profit"))
m %>%
addCircleMarkers(color = ~pal(sector_label))
Neden özellikle bu renk paletini kullanmak istemeyebiliriz?
Bir haritayı renklendirmek için sürekli bir değişken kullanmak istersen colorNumeric() fonksiyonuna bakabilirsin.
pal <- colorNumeric(palette = "RdBu", domain = c(25:50))
ipeds %>%
leaflet() %>%
addProviderTiles("CartoDB") %>%
addCircleMarkers(radius = 2, color = ~pal(lat))
Bu egzersiz, kursun bir parçasıdır
R ile leaflet kullanarak Etkileşimli Haritalar
Egzersiz talimatları
colorFactor()kullanaraksector_labeldeğerleri için "red", blue" ve "#9b4a11" renklerinden oluşanpaladlı bir renk paleti oluştur.- Üniversiteleri
sector_labeldeğerleriylepal()kullanarak renklendiren dairesel işaretçiler ekle.
Uygulamalı etkileşimli egzersiz
Bu egzersizi bu örnek kodu tamamlayarak deneyin.
# Make a color palette called pal for the values of `sector_label` using `colorFactor()`
# Colors should be: "red", "blue", and "#9b4a11" for "Public", "Private", and "For-Profit" colleges, respectively
pal <- ___(palette = c("red", "blue", ___),
levels = c("Public", "Private", "For-Profit"))
# Add circle markers that color colleges using pal() and the values of sector_label
map2 <-
map %>%
addCircleMarkers(data = ca, radius = 2,
color = ~pal(sector_label),
label = ~paste0(name, " (", sector_label, ")"))
# Print map2
map2