Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在漏斗图中居中_R_Ggplot2_Geom Bar - Fatal编程技术网

R 在漏斗图中居中

R 在漏斗图中居中,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,我试图在R中制作漏斗图。作为一个例子,我从这个页面中获取了代码 但奇怪的是,我无法理解,为什么我的铁条会向左倾斜 Funnel data: Category Number 1 total_members 1000 2 paid_members 936 3 cancellations 452 4 refunds 34 library(ggplot2) ggplot() + theme_minimal() + coord_flip()

我试图在R中制作漏斗图。作为一个例子,我从这个页面中获取了代码 但奇怪的是,我无法理解,为什么我的铁条会向左倾斜

Funnel data: 

       Category Number
1 total_members   1000
2  paid_members    936
3 cancellations    452
4       refunds     34

library(ggplot2)
ggplot() +
  theme_minimal() +
  coord_flip() +
  scale_fill_manual(values=cols)+
  geom_bar(data=funnel_data, aes(x=Category, y=Number, fill=Category), stat="identity", width=1)
导致

如果您只是运行本文中的一段代码,例如:

ggplot() +
  theme_minimal() +
  coord_flip() +
  scale_fill_manual(values=cols) +
  geom_bar(data=df.all, aes(x=step, y=number, fill=content), stat="identity", width=1)
它将为您提供一个以X为中心的条形图的好例子:


我不知道这个案子有什么问题。如果有任何帮助,我将非常高兴

这是不同的方法,但有效-创建第二个
geom\u条
geom和负值:

library(ggplot2)
# Using OPs data
ggplot(funnel_data, aes(Category, fill = Category)) +
    geom_bar(aes(y =  Number), stat = "identity", width = 1) + 
    geom_bar(aes(y = -Number), stat = "identity", width = 1) +
    theme_minimal() +
    coord_flip()

@Фаажз乐意帮忙