ggplot2 geom_area重叠区域在彼此前面绘制 [英] ggplot2 geom_area overlay area plots in front of each other
问题描述
我有一个看起来像这样的数据框:
我试图做一个区域情节与不同区域叠加在一起,而不是堆叠。 p>
r变量值
1 45.0猫1 4.057250e + 03
2 52.5猫1 3.537323e + 03
3 56.1猫1 3.429861e + 03
4 57.3猫1 3.395330e + 03
5 57.6猫1 3.389983e + 03
6 45.0猫2 4.545455e-03
7 52.5 Cat 2 4.509400e + 01
8 56.1 Cat 2 3.525753e + 02
9 57.3 Cat 2 4.185094e + 02
10 57.6 Cat 2 4.336622e + 02
11 45.0 Cat 3 4.074432e + 03
12 52.5 Cat 3 3.630504e + 03
13 56.1 Cat 3 3.919076e + 03
14 57.3 Cat 3 3.957039e + 03
15 57.6 Cat 3 3.970083e + 03
16 45.0类别4 1.718182e + 01
17 52.5类别4 9.318133e + 01
18 56.1类别4 4.892154e + 02
19 57.3类别4 5.617087 e + 02
20 57.6 Cat 4 5.801001e + 02
我正在尝试为每个类别获取面积图。我的代码是:
p < - ggplot(reshaped_data,aes(r,value))
p< ; - p + labs(x =X Axis,y =Y Axis)+ ggtitle(title)
p <-p + geom_area(aes(color = variable,fill = variable),position =' stack')
p
我得到的结果如下所示:
我怎样才能使面积图不会彼此堆叠,但最小的是覆盖在前面更大的?
谢谢 使用<$ c
$ p $ library $($) =变量,
fill = fct_reorder(变量,值,.desc = TRUE)),position ='identity')
删除 .desc = TRUE
如果它这与你想要的相反。
I am trying to make an area plot with the different areas are overlaid on one another rather than stacked.
I have a dataframe that looks like this:
r variable value
1 45.0 Cat 1 4.057250e+03
2 52.5 Cat 1 3.537323e+03
3 56.1 Cat 1 3.429861e+03
4 57.3 Cat 1 3.395330e+03
5 57.6 Cat 1 3.389983e+03
6 45.0 Cat 2 4.545455e-03
7 52.5 Cat 2 4.509400e+01
8 56.1 Cat 2 3.525753e+02
9 57.3 Cat 2 4.185094e+02
10 57.6 Cat 2 4.336622e+02
11 45.0 Cat 3 4.074432e+03
12 52.5 Cat 3 3.630504e+03
13 56.1 Cat 3 3.919076e+03
14 57.3 Cat 3 3.957039e+03
15 57.6 Cat 3 3.970083e+03
16 45.0 Cat 4 1.718182e+01
17 52.5 Cat 4 9.318133e+01
18 56.1 Cat 4 4.892154e+02
19 57.3 Cat 4 5.617087e+02
20 57.6 Cat 4 5.801001e+02
I am trying to get area plots for each category. My code for that is:
p <- ggplot(reshaped_data, aes(r, value))
p <- p + labs(x = "X Axis", y = "Y Axis") + ggtitle(title)
p <- p + geom_area(aes(colour = variable, fill= variable), position = 'stack')
p
And the result I am getting looks like this:
How can I make it so that the area graphs aren't stacked on each other, but the smallest are overlaid in front of the bigger ones?
Thanks
Using tidyverse
:
library(forcats)
p + geom_area(aes(colour = variable,
fill= fct_reorder(variable, value, .desc = TRUE)), position = 'identity')
Remove .desc = TRUE
if it does the opposite of what you want.
这篇关于ggplot2 geom_area重叠区域在彼此前面绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!