如何使极坐标的角度与 ggplot2 中的曝光比例相关?

How can I make the angles of my polar coordinates relate to exposure proportions in ggplot2?

假设我在R中有以下数据:

mydata <- data.frame(Group=1:5, Profit=seq(60, 100, by=10), 
Count=seq(50000, 10000, by=-10000))

我可以绘制一个条形图来显示按组划分的利润:

r1 <- ggplot(data=mydata, aes(x=Group, y=Profit, fill=Group))
r1 + 
  geom_bar(stat="identity") +
  scale_fill_gradient(low="khaki", high="turquoise4") +
  labs(title="Group 5 is the most profitable segment") 

我还可以绘制一个饼图,显示按组显示的曝光比例(计数):

r2 <- ggplot(data=mydata, aes(x="", y=Count, fill=Group))
r2 + 
  geom_bar(width=1, stat="identity") +
  scale_fill_gradient(low="khaki", high="turquoise4") +
  coord_polar(theta="y", start=0) +
  labs(title="We have significant exposure in lower Groups") 

我想做的是结合以上内容,使饼图的角度与每个组级别的曝光比例相关,就像在 r2 中一样,但也与 increase/decrease 每个组的大小相关"slice"(即半径)根据r1中每个Group级别的利润。

感谢收到的任何帮助。

谢谢

library(dplyr)
mydata %>%
  mutate(end_count = cumsum(Count),  # or add "/sum(Count)" to make it "out of 100%"
         start_count = lag(end_count, default = 0)) %>%
  ggplot() +
  geom_rect(aes(xmin = start_count, xmax = end_count,
                ymin = 0, ymax = Profit, fill=Group)) +
  scale_fill_gradient(low="khaki", high="turquoise4") +
  coord_polar(theta="x", start=0) +
  labs(title="We have significant exposure in lower Groups")