0

I am testing choroplethr and choroplethrmaps in Hong Kong Map. I want to show the region in Hong Kong and the vote. following is what I have done in R. But it does not work. Could you help me how can I do it?

install.packages(c("choroplethr", "choroplethrMaps"))
library(choroplethr)
setwd('/Users/hkawngnaw/Downloads')
hkmap <- readRDS("HKG_adm1.rds")
map(hkmap)
hkelection<-data.frame(c('Central and Western','Wan Chai','Eastern','Southern','Yau Tsim Mong','Sham Shui Po','Kowloon City','North','Tai Po','Sai kung','Sha Tin'))
hkelection$VOTE<-c(23307,14165,67685,32023,24907,11395,42691,27193,34183,45697,76686)
colnames<-c('Region','Value')
allcandidates$Region = allcandidates$Value
state_choropleth(allcandidates)
Prashant Pokhriyal
  • 3,727
  • 4
  • 28
  • 40

1 Answers1

0

There are a few issues here.

The main issue is that the function state_choropleth is designed to map US States, but you are giving it data to map Hong Kong administrative regions. You can see this by reading the help for the function state_choropleth. You can do that by typing ?state_choropleth.

Choroplethr can indeed map Hong Kong subdivisions. But to use that functionality, you need to use the function ?admin1_choropleth. That function is in the package choroplethrAdmin1. Here is some documentation on how that package works.

Lastly, the code snippet that you included in your question is not reproducible. It includes setting the working directory to a directory that I don't have, and loading a file that I don't have. In the future, I recommend making your question "reproducible". You can learn more about that here.

Ari
  • 1,819
  • 14
  • 22