Prometheus
Prometheus

Reputation: 2017

Chaning labels in choropleth hcmap

I have the following dataset:

    structure(list(code = structure(1:6, .Label = c("?elino", "?tip", 
"?uto Orizari", "Aerodrom", "Aracinovo", "Berovo", "Bitola", 
"Bogdanci", "Bogovinje", "Bosilovo", "Brod", "Brvenica", "Butel", 
"Ca?ka", "Cair", "Ce?inovo-Oble?evo", "Centar", "Centar ?upa", 
"Cucer Sandevo", "Debar", "Debarca", "Delcevo", "Demir Hisar", 
"Demir Kapija", "Dojran", "Dolneni", "Drugovo", "Gazi Baba", 
"Gjorce Petrov", "Gostivar", "Gradsko", "Ilinden", "Jegunovce", 
"Karbinci", "Karpo?", "Kavadartsi", "Kicevo", "Kisela Voda", 
"Kocani", "Konce", "Kratovo", "Kriva Palanka", "Krivoga?tani", 
"Kru?evo", "Kumanovo", "Lipkovo", "Lozovo", "Makedonska Kamenica", 
"Mavrovo and Rostusa", "Negotino", "Northeastern", "Novatsi", 
"Novo Selo", "Ohrid", "Oslomej", "Pelagonia", "Phecevo", "Plasnica", 
"Polog", "Prilep", "Probistip", "Radovis", "Rankovce", "Resen", 
"Saraj", "Skopje", "Sopiste", "Southeastern", "Struga", "Studenicani", 
"Sveti Nikole", "Tearce", "Tetovo", "Valandovo", "Vardar", "Vasilevo", 
"Veles", "Vev?ani", "Vinitsa", "Vrane?tica", "Zajas", "Zelenikovo", 
"Zrnovci"), class = "factor"), value = c(48L, 1810L, 205L, 1507L, 
38L, 66L), OPSTINA_NAZIV = c("ЖЕЛИНО", "ШТИП", "ШУТО ОРИЗАРИ", 
"АЕРОДРОМ", "АРАЧИНОВО", "БЕРОВО"), `postal-code` = c("ZE", "ST", 
"SO", "AD", "AR", "BR")), .Names = c("code", "value", "OPSTINA_NAZIV", 
"postal-code"), row.names = c(NA, 6L), class = "data.frame")

and I'm plotting a choropleth map with the hcmap function below:

hcmap("countries/mk/mk-all.js", data = data_fake,
      name = "Manucipalities", value = "value", joinBy = c("name", "code"),
      borderColor = "transparent") %>%
  hc_colorAxis(dataClasses = color_classes(c(seq(0, 2000, by = 500), 13000))) %>% 
  hc_legend(layout = "vertical", align = "right",
            floating = TRUE, valueDecimals = 0, valueSuffix = "")  %>%
hc_mapNavigation(enabled = TRUE)

However, at the moment the labels that appear on the map are from the "code" variable, which contain encoding problems. I want to plot the labels from the "OPSTINA_NAZIV" label.

Any ideas how I can do this?

I tried:

  dataLabels = list(enabled = TRUE, format = '{point.OPSTINA_NAZIV}')

But it didn't work out.

Upvotes: 0

Views: 165

Answers (1)

jbkunst
jbkunst

Reputation: 3029

You can access to the mapData info using the options accesor. Example {point.options.OPSTINA_NAZIV}:

hcmap("countries/mk/mk-all.js", data = data_fake,
      name = "Manucipalities", value = "value", joinBy = c("name", "code"),
      borderColor = "transparent" ,
      dataLabels = list(enabled = TRUE, format = "{point.options.OPSTINA_NAZIV}"))

mapchart

Upvotes: 1

Related Questions