2017-11-10 19 views
0

R에서 깔때기 형 차트를 만들려고합니다. 예를 들어이 페이지에서 코드를 가져 왔습니다. https://analyzecore.com/2015/06/23/sales-funnel-visualization-with-r/ 이상한 점은 내가 얻을 수 없었던 것입니다. 왜 내 막대가 왜곡되어 있습니다. 왼쪽?깔때기 형 차트 중앙에 막대기

enter image description here

에서

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를 중심으로 한 막대 : enter image description here

이 경우 어떤 문제인지 실마리가 없습니다. 어떤 도움을 주셔서 감사합니다.

답변

1

이 다른 접근이지만, 작품 - 음의 값을 갖는 두 번째 geom_bar 기하 구조 생성 :

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() 

enter image description here

+1

아, 덕분에 많은이가 도와 드리겠습니다 ФанкиДжаз @ –

+0

도움 – PoGibas