当包没有此功能时如何调整 R 中人体图的线宽

发布于 2025-01-09 15:29:00 字数 864 浏览 0 评论 0原文

我正在使用 CHOIRBM 包(https://github.com/emcramer/CHOIRBM)并制作一张显示全身患病率和疼痛的身体图。我想改变身体图本身的线条粗细,但该包似乎没有该选项。该包是在 ggplot 包之上构建的,所以我想知道是否有某种我不知道的 ggplot 命令可以做到这一点。 这是代码。请注意,id= 身体区域,Percent= 疼痛百分比,group= 身体正面或背面。包装要求物品以这种方式贴上标签。这就是地图的样子:

在此处输入图像描述

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))

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))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2025-01-16 15:29:00

似乎没有直接的方法可以做到这一点,但您可以间接地做到这一点,因为它最终是由geom_polygon构建的。首先存储绘图:

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

在此处输入图像描述

现在您将覆盖多边形图层的尺寸美感:

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

p

在此处输入图像描述

请注意,多边形可能不再完美重叠。


从 GitHub 示例生成的数据

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")
)

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")
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文