How to adjust line width of a bodymap in R when package doesn't have this function

Viewed 65

I am working with the CHOIRBM package (https://github.com/emcramer/CHOIRBM) and made a body map looking at prevalence and pain throughout the body. I want to alter the thickness of the lines on the bodymap itself but the package doesn't appear to have that option. The package was built on top of the ggplot package however so I was wondering if there was some type of ggplot command that I'm not aware that will do this. Here is the code. Note that id= region of the body, Percent= percent of pain, and group= front or back of body. The package requires things to be labeled this way. And this is what the map looks like:

enter image description here

painF %>% filter(value == 1) %>% select(id, Percent, group) %>%                
plot_female_choirbm(value="Percent") +
scale_fill_gradient(low="white", high="red", limits=c(0,10)) +
theme(legend.position = "bottom") +
labs(fill = "Prevelance of pain (%)")+                                
ggtitle(" " , subtitle="Female")+
theme(plot.subtitle=element_text(face="bold", hjust=0.5))
1 Answers

There doesn't seem to be a direct way to do this, but you can do it indirectly since it is built ultimately out of geom_polygon. First store the plot:

p <- plot_female_choirbm(values, "value")  +
scale_fill_gradient(low="white", high="red", limits=c(0,10)) +
theme(legend.position = "bottom") +
labs(fill = "Prevelance of pain (%)")+                                
ggtitle(" " , subtitle="Female")+
theme(plot.subtitle=element_text(face="bold", hjust=0.5))

p

enter image description here

Now you overwrite the size aesthetic of the polygon layer:

p$plot_env$p$layers[[1]]$aes_params$size <- 0.5

p

enter image description here

Note that the polygons may no longer overlap perfectly any more.


Data generated from GitHub example

library(CHOIRBM)

# generate some random example data
set.seed(123)
ids <- as.character(c(seq.int(101, 136, 1), seq.int(201, 238, 1)))
values <- data.frame(
  id = ids
  , value = runif(length(ids), 0, 10)
  , ucolors = rainbow(length(ids))
  , group = ifelse(as.numeric(ids) < 200, "Front", "Back")
)
Related