dictionary - Cartography in R - how to plot numeric and binary values on a map? -


i'm trying produce 2 maps, 1 multiple categoric values , 1 continous numeric values, in:

link

i have dataset provides npa , 2 informations each npa: item (category) , frequency (on scale 1 10):

npa     item           frequency 1000    huitante        0 1002    huitante        10 1006    quatre-vingt    3 2000    huitante        9 

i have specific shapefile country work on (switzerland). on previous post, found interesting code, copy/paste here:

# open shapefile require(rgdal) require(rgeos) require(ggplot2) ch <- readogr(work.dir, layer = "plzo_plz")  # convert data frame plotting ggplot - takes while ch.df <- fortify(ch)  # generate fake data , add data frame ch.df$count <- round(runif(nrow(ch.df), 0, 100), 0)  # plot ggplot ggplot(ch.df, aes(x = long, y = lat, group = group, fill = count)) + geom_polygon(colour = "black", size = 0.3, aes(group = group)) + theme() 

the author gives in comment information plot specific dataset (and not fake data):

# plot subset of npas using ggplot my.sub <- ch.df[ch.df$id %in% c(4,6), ] ggplot(my.sub, aes(x = long, y = lat, group = group, fill = count)) + geom_polygon(colour = "black", size = 0.3, aes(group = group)) + theme() 

and says in comment of post :

replace ggplot(my.sub, aes(x = long, y = lat, group = group, fill = count)) ggplot(my.sub, aes(x = long, y = lat, group = group, fill = frequency))

so guess need extract frequency variable

frequency <- table(data$frequency) 

and change in code indicated in quote.

unfortunately, problem not work, following comment :

don't know how automatically pick scale object of type table. defaulting continuous error: aesthetics must either length one, or same length dataproblems:frequency

my questions :

  • how can change code include own data, , plot numeric value (frequency)
  • how can change code include own data, , plot categoric value (item)

i don t need represent frequency , item on same map, know how create seprated maps.

my dataset in file, shapefile need use.

https://www.dropbox.com/sh/5x6r6s2obfztblm/aaaesiorxn76hu57aif0y1oua?dl=0

any appreciated!


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -