Hello. I'm trying to do a choropleth map but I have the following issue:
I woud like to know what am I doing wrong.
Here is my code:
I commented those lines because I tried in the 2 ways but neither works
This is the way how I tried to do the plot:
I would like to know how to fix that issue. Thanks in advance!
Choropleth map
Re: Choropleth map
hi,
there's an R concept you're missing. you've defined 'long' inside of .run() ... but you need to use a mechanism to get access to 'long' from inside of .plot() ... the way we normally pass these things around, is using image$setState(...) and then we can access it inside .plot() with image$state
cheers
jonathon
there's an R concept you're missing. you've defined 'long' inside of .run() ... but you need to use a mechanism to get access to 'long' from inside of .plot() ... the way we normally pass these things around, is using image$setState(...) and then we can access it inside .plot() with image$state
cheers
jonathon
Re: Choropleth map
Ohh got it. Thanks! I fixed that, but now I have other problem:
I tried to fix it with this code:
I don't know what am I doing wrong. I'm still new in creating modules.
I really appreciate your help. Thanks in advance!
I tried to fix it with this code:
I don't know what am I doing wrong. I'm still new in creating modules.
I really appreciate your help. Thanks in advance!
Re: Choropleth map
Hey @rovargasc,
maybe my code can help you (similar to what you are doing) that I made on the fly some time ago and left in a drawer, to improve it later.
Cheers,
Maurizio
maybe my code can help you (similar to what you are doing) that I made on the fly some time ago and left in a drawer, to improve it later.
Code: Select all
## file: mappa.b.r per modulo jamovi coromap
## data: 17/03/2022
mappaClass <- if (requireNamespace('jmvcore', quietly=TRUE)) R6::R6Class(
"mappaClass",
inherit = mappaBase,
private = list(
.run = function() {
long <- self$options$long
lat <- self$options$lat
group <- self$options$group
misure <- self$options$misure
varNames <- c(long, lat, group, misure)
if (is.null(long) || is.null(lat) || is.null(group) || is.null(misure))
return()
Dataset <- jmvcore::select(self$data, varNames)
image <- self$results$plot
image$setState(Dataset)
},
.plot=function(image, ...){
Dataset <- image$state
PlotData <- Dataset[,1:4]
colnames(PlotData) <- c('long', 'lat', 'group', 'misure')
p <- ggplot2::ggplot() +
ggplot2::geom_polygon(data=PlotData,
aes(x=long,
y=lat,
group=group,
fill=misure),
color='white',
size = 0.2) +
ggplot2::coord_map('polyconic') +
ggplot2::scale_fill_gradient2(low="#559999",
mid="grey90",
high="#BB650B",
midpoint=median(misure))+
ggplot2::scale_fill_viridis_c()
print(p)
TRUE
}
)
)
Maurizio
Re: Choropleth map
Thanks MAgojam! I tried your code, but I'm still having some problems, check it out:
This is how my data looks like:
This is how my data looks like:
Re: Choropleth map
Hey @rovargasc,
if you give me a link (GitHub) to your code, I can take a look and maybe help you.
Saudações,
Maurizio
if you give me a link (GitHub) to your code, I can take a look and maybe help you.
Saudações,
Maurizio
Re: Choropleth map
Okay. This is the link: https://github.com/rovargasc/coroplethmap
These are the files, I tried to do what you have done, but it doesn't work for me...
I really appreciate your help. Thanks!
These are the files, I tried to do what you have done, but it doesn't work for me...
I really appreciate your help. Thanks!
Re: Choropleth map
Hey @rovargasc,
I took a look at your module on GitHub and made a few changes.
Now your form does this: I think you can go on to complete it (you have my link for that).
Cheers,
Maurizio
I took a look at your module on GitHub and made a few changes.
Now your form does this: I think you can go on to complete it (you have my link for that).
Cheers,
Maurizio