sankey /冲积图,其中百分比和部分填充为R

问题描述

我想使用[pid].js//ProductDetails function... export async function getStaticProps() { //I wanna have the dynamic route placed on the URL string below const res = await fetch('https://meli-345234234.firebaseio.com/catalog.json') const number = await res.json() return { props: { number: number } } } export async function getStaticPaths() { //must repeat this here as I am using a dynamic route const res = await fetch('https://meli-345234234.firebaseio.com/catalog.json') const data = await res.json() return { paths: [ { params: { pid: '1' } },{ params: { pid: '2' } } ],fallback: true }; } 修改现有的sankey图,使其更具吸引力

我的示例来自https://corybrunson.github.io/ggalluvial/articles/ggalluvial.html

ggplot2

reprex package(v0.3.0)于2020-10-01创建

现在,我想更改此图,使其看起来类似于https://sciolisticramblings.wordpress.com/2018/11/23/sankey-charts-the-new-pie-chart/中的图,即1.将绝对值更改为相对值(百分比)2.添加百分比标签,并3.应用部分填充(例如“缺少”和“从不”)

enter image description here

我的方法 我想我可以将轴更改为百分比,例如:ggalluvial 但是,我不确定步骤2和3。

解决方法

可以这样实现:

  1. 要更改百分比,可以在df中添加一个新的列,其中包含按比例划分的百分比份额,然后可以将其映射到y而不是freq上。

  2. 要获得不错的百分比标签,您可以使用scale_y_continuous(label = scales::percent_format())

  3. 对于部分填充,您可以映射例如response %in% c("Missing","Never")上的fill(将TRUE表示为“缺少”和“从不”),并通过scale_fill_manual设置填充颜色

  4. 每个阶层的百分比都可以通过label = paste0(..stratum..,"\n",scales::percent(..count..,accuracy = .1))中的geom_text添加到标签中,其中我使用了{计算的变量..stratum....count.. {1}}。

stat_stratum

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...