我竭尽所能地寻找解决方案.我能找到的最接近的是这个,但它并不是我想要的.
我试图模拟一个值与其父值之间的关系.特别是试图计算比率.我还想跟踪血统的水平,比如这个项目有多少孩子?
例如,我想输入一个如下所示的pandas df:
id parent_id score
1 0 50
2 1 40
3 1 30
4 2 20
5 4 10
Run Code Online (Sandbox Code Playgroud)
得到这个:
id parent_id score parent_child_ratio level
1 0 50 NA 1
2 1 40 1.25 2
3 1 30 1.67 2
4 2 20 2 3
5 4 10 2 4
Run Code Online (Sandbox Code Playgroud)
因此,对于每一行,我们都会找到其父级的分数,然后计算(parent_score/child_score)并使其成为新列的值.然后某种计数解决方案增加了孩子的水平.
这一直困扰我一段时间,任何帮助表示赞赏!!!
我分叉了ggthemes git repo来制作我自己的自定义主题。我已经想出了如何做几乎所有我需要的事情,但有一个挂断电话。
我特别想设置默认size为geom_line()我的ggtheme。
我现在在哪里,我必须做这样的事情:
economics %>%
ggplot(aes(date, uempmed)) +
geom_line(size = 1.75) +
theme_mycustomtheme()
Run Code Online (Sandbox Code Playgroud)
当我更愿意只需要这样做时:
economics %>%
ggplot(aes(date, uempmed)) +
geom_line() +
theme_mycustomtheme() # this would set the line size automatically
Run Code Online (Sandbox Code Playgroud)
我已经编辑了 mycustomtheme.R 文件,如下所示:
theme(
# Elements in this first block aren't used directly, but are inherited
# by others
line = element_line(
color = "black", size = 1.75,
linetype = 1, lineend = "butt"
)
Run Code Online (Sandbox Code Playgroud)
请注意大小现在如何设置为 1.75。但是当我在实践中调用主题时,它似乎没有什么不同。
我将不胜感激任何关于我可能做错了什么的指示。谢谢!