riatelab / mapsf

Thematic cartography with R

Home Page:https://riatelab.github.io/mapsf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plotting single points ?

Thomzoy opened this issue · comments

Hello,

I have an issue when trying to plot a single value with mf_map. For instance:

mtq<-mf_get_mtq()
mf_map(mtq)
mf_map(mtq[1,], var = c("POP", "STATUS"), type = "prop_typo")

Returns

Error in xy.coords(x, y, xlab = deparse1(substitute(x)), ylab = deparse1(substitute(y))) : 
  'x' is a list, but does not have components 'x' and 'y'

The problem actually remains when only a single row has a non-zero POP:

tmp<- mtq[0:2,]
tmp$POP<-c(10,0)
mf_map(mtq)
mf_map(tmp, var = c("POP", "STATUS"), type = "prop_typo")

returns the same error.

Is there something I'm doing wrong ? Thanks for the help.

I'm AFK right now, I'll look into it next week.

Hello,

I'm not sure if classify intervals works with just one record or two records. Is it really necessary or is it a just instance?

Sure, it may not be very useful to plot just one proportional symbol, it's an edge case. But at least it should fail gracefully (or work :-))

Well in my case this situation occurred quite naturally when iterating over multiple territories: some of them had only one point to plot, and it would be quite natural to be able to plot them as the other ;)

Well in my case this situation occurred quite naturally when iterating over multiple territories: some of them had only one point to plot, and it would be quite natural to be able to plot them as the other ;)

That's a perfectly legitimate case. I'll be able to work on this bug on Thursday.

Commit f702f26 should have fixed the problem.
reprex:

library(mapsf)
mtq <- mf_get_mtq()
opar <- par(mfrow = c(3,4))
mf_theme(x = "dark")
for( i in 9:18){
  mf_map(mtq)
  mf_map(x = mtq[i, ], var = c('POP', 'STATUS'), type = "prop_typo", 
         symbol = "circle",inches = .2,        
         val_order = c('Prefecture', "Sub-prefecture", "Simple municipality"),
         pal = c("red", "blue", "green"),
         val_max = max(mtq$POP), leg_pos = c(NA,NA))
  mf_title(mtq[i,"LIBGEO", drop = TRUE])
}
# legends
mf_theme(bg = NA)
mf_init(mtq)
mf_legend(type = "prop", pos = "top", title = "Population",
          val = c(min(mtq$POP), 10000, 40000, max(mtq$POP)),
          inches = .2, col = "grey80",
          cex = 2, title_cex = 1.5, val_cex = 1)
mf_init(mtq)
mf_legend(type = "typo", pos = "top", title = "Status",
          val =  c('Prefecture', "Sub-prefecture", "Simple municipality"), 
          pal = c("red", "blue", "green"),
          cex = 1.5, title_cex = 1.5, val_cex = 1)
par(opar)

Created on 2022-11-03 with reprex v2.0.2