用Facet包装创建饼图?

发布于 2025-02-14 01:40:10 字数 159 浏览 0 评论 0原文

如图所示,我设法创建了一个数据框架,但我不知道如何从中创建刻面饼图。有人可以告诉我如何吗?提前致谢。 在此处输入图像描述

I manage to create a dataframe as shown but I dont know how to create faceted pie charts out of it. Can someone show me how? Thanks in advance.
enter image description here

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

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

发布评论

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

评论(1

枫林﹌晚霞¤ 2025-02-21 01:40:10

我不确定您想显示什么,所以您可以做这样的事情:

df <- data.frame(rideable_type = c("classic_bike", "classic_bike", "docked_bike", "electric_bike", "electric_bike"),
                 member_causal = c("causal", "member", "causal", "causal", "member"),
                 number_of_bikes = c(1313878, 2013712, 308241, 1048194, 1250025),
                 total = c(2670303, 3263737, 2670303, 2670303, 3263737),
                 freq = c(49.2, 61.6, 11.5, 39.2, 38.3))


library(ggplot2)
ggplot(df, aes(x = factor(1), fill=factor(rideable_type))) + 
  facet_wrap(~member_causal) + 
  geom_bar(width = 1,position = "fill") + 
  coord_polar(theta="y") +
  labs(fill = "rideable type", x = "", y = "") 

“”

在2022-07创建-08 by reprex软件包(v2.0.1)

I am not sure what you want to show, so you could do something like this:

df <- data.frame(rideable_type = c("classic_bike", "classic_bike", "docked_bike", "electric_bike", "electric_bike"),
                 member_causal = c("causal", "member", "causal", "causal", "member"),
                 number_of_bikes = c(1313878, 2013712, 308241, 1048194, 1250025),
                 total = c(2670303, 3263737, 2670303, 2670303, 3263737),
                 freq = c(49.2, 61.6, 11.5, 39.2, 38.3))


library(ggplot2)
ggplot(df, aes(x = factor(1), fill=factor(rideable_type))) + 
  facet_wrap(~member_causal) + 
  geom_bar(width = 1,position = "fill") + 
  coord_polar(theta="y") +
  labs(fill = "rideable type", x = "", y = "") 

Created on 2022-07-08 by the reprex package (v2.0.1)

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