问题描述
我想使用[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.应用部分填充(例如“缺少”和“从不”)
我的方法:
我想我可以将轴更改为百分比,例如:ggalluvial
但是,我不确定步骤2和3。
解决方法
可以这样实现:
-
要更改百分比,可以在df中添加一个新的列,其中包含按比例划分的百分比份额,然后可以将其映射到
y
而不是freq
上。 -
要获得不错的百分比标签,您可以使用
scale_y_continuous(label = scales::percent_format())
-
对于部分填充,您可以映射例如
response %in% c("Missing","Never")
上的fill
(将TRUE
表示为“缺少”和“从不”),并通过scale_fill_manual
设置填充颜色 -
每个阶层的百分比都可以通过
label = paste0(..stratum..,"\n",scales::percent(..count..,accuracy = .1))
中的geom_text
添加到标签中,其中我使用了{计算的变量..stratum..
和..count..
{1}}。
stat_stratum