[R填写geom_point百分比

问题描述 投票:2回答:1

我想提出一个圆图,其中在rec列中的值对应于应该充满黑色圆的百分比。我提出在Photoshop(参见图1中OBS A和B)的例子。在我的搜索,我发现了bar_plot一些解释,但他们都不在我的脚本工作

有没有人知道如何做到这一点或暗示另一个图表选项,将显示出我想要的东西?

ggplot(Dataset, aes(sp,log(num))) + 
  geom_point(aes(size = pref, color=as.factor(ex)), shape = 21, stroke = 2)+
  scale_size_continuous(range = c(4,10)) +
  scale_colour_manual(values=c("black", "red")) + # set the border to the bg color
  ggthemes::theme_few() +
  guides(color = FALSE) + # remove the legend for the border
  theme(axis.text.x = element_text(angle = 90, vjust = .5))

数据:

grupo   sp  num porc_rec    rec pref    ex
ave A   47  74.46808511 35  7   0
ave B 22    22.72727273 5   3   0
ave C   5   0   0   0   0
ave D   4   0   0   0   0
ave E   2   0   0   0   0
ave F   2   0   0   0   0
ave G   2   0   0   0   1
ave H   2   0   0   0   0
ave I   1   0   0   1   0
ave J   1   0   0   0   0
ave L 1 0   0   0   0
ave M   1   0   0   0   0
ave N   1   0   0   0   0
ave O   1   0   0   0   0
ave P   1   0   0   0   0
ave Q   1   0   0   0   0
ave R   1   0   0   0   0
ave S   1   0   0   0   1
ave T   1   0   0   0   1
ave U   1   0   0   0   1

enter image description here

r ggplot2 geometry percentage point
1个回答
2
投票

使用scatterpie包,你可能会产生类似于你问什么(半径比例是不完美的,但应该是调整,以获得您想要的结果的东西:

dat = structure(list(group = c("ave", "ave", "ave", "ave", "ave", "ave", 
        "ave", "ave", "ave", "ave", "ave", "ave", "ave", "ave", "ave", 
        "ave", "ave", "ave", "ave", "ave"), sp = c("A", "B", "C", "D", 
        "E", "F", "G", "H", "I", "J", "L", "M", "N", "O", "P", "Q", "R", 
        "S", "T", "U"), num = c(47L, 22L, 5L, 4L, 2L, 2L, 2L, 2L, 1L, 
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), porc_rec = c(74.46808511, 
        22.72727273, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0), rec = c(35L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), pref = c(7L, 3L, 0L, 0L, 0L, 
        0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 
        ex = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L, 0L, 0L, 1L, 1L, 1L)), class = "data.frame", row.names = c(NA, 
        -20L))

library(ggplot2)
library(scatterpie)

dat$idx = as.numeric(1:nrow(dat))

input = dat[,c("idx","num","porc_rec","ex","pref")]
input$recip = 100 - input$porc_rec
input$radius = abs(0.4 / scale((input$pref + 1)/ max(input$pref),center = 7))
ggplot() + geom_scatterpie(data=input, aes(x=idx, y=log(num),color = factor(ex), r = radius), cols=c("porc_rec","recip")) +
  coord_equal() +
  scale_fill_manual(values = c("black","white")) + scale_colour_manual(values = c("black","red"))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.