一个图中的每个轴是否有单独的因子水平?

发布于 2025-01-21 12:17:58 字数 838 浏览 5 评论 0原文

我正在尝试绘制源国家和同行国家之间的金融流量图。

ggplot(dat_ggforce, aes(x=x, id=id, split = y, value=yvalue)) +
geom_parallel_sets(aes(fill = cpcountryname), alpha = alpha, axis.width = 0.2,
                   n=100, strength = 0.6)

但是,我使用因子水平订购了全国名称和cpcountryname

dat$countryname <- factor(dat$countryname, levels = c("Indonesia", "Malaysia", "Philippines", "Singapore", "Thailand"))
dat$cpcountryname <- factor(dat$cpcountryname, levels = c("United States","United Kingdom","Japan","Malaysia", "Others")

,因为马来西亚在左侧和右轴上,马来西亚突然突然覆盖了右轴:

“马来西亚是顶部,而不是第五层”

编辑:交易对手国家的订单基于流量大小(US&GT; UK&GT; JP&GT; ME,然后是其他人)。马来西亚应在日本的右轴上以下,如CPCountryname的因子水平所示,但一直处于最高水平。

Edit2:我已经缩小了问题。我的实际问题是,是否可以在一个图中为每个轴具有单独的因子水平吗?

I'm trying to plot a Sankey diagram of financial flows between a source country and counterpart country.

ggplot(dat_ggforce, aes(x=x, id=id, split = y, value=yvalue)) +
geom_parallel_sets(aes(fill = cpcountryname), alpha = alpha, axis.width = 0.2,
                   n=100, strength = 0.6)

I order countryname and cpcountryname using factor levels

dat$countryname <- factor(dat$countryname, levels = c("Indonesia", "Malaysia", "Philippines", "Singapore", "Thailand"))
dat$cpcountryname <- factor(dat$cpcountryname, levels = c("United States","United Kingdom","Japan","Malaysia", "Others")

However, because Malaysia is in both the left and right axis, Malaysia suddenly overrides the right axis, as such:

Malaysia is at top instead of 5th stratum

Edit: The order for counterparty country is based on flow size (US > UK > JP > MY, then others). Malaysia should be below Japan on the right axis as seen in the factor levels for cpcountryname, but keeps moving to the top.

Edit2: I have narrowed the problem. My actual question is, is it possible to have separate factor levels for each axis in one graph?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文