2013-05-10 100 views
0

我在ggplot2中有問題。如果我重新排列因子水平並繪製文本標籤值(在這種情況下是頻率),則文本標籤值仍保留在舊的級別中。 有什麼問題? enter image description hereggplot2中的重排因子水平不適合y geom_text註釋

29和71是頻率,但我想要適合29綠線和71紅線。如果你扭轉陰謀,數字很適合! Thaaanks 下面圖表的代碼:

with(data4, 
    ggplot(subset(data4,ASSAGGIATORE=="Manera"), 
      aes(ASSAGGIATORE,Freq,fill=SCELTA)) + 
     geom_bar() + 
     geom_text(aes(label=round(Freq)), 
       position="stack") + 
     scale_size(range=c(5,6)) +     
     geom_hline(aes(yintercept=mediana), 
        colour="navy", 
        linetype="dotted") + 
     scale_fill_manual(values=c("chartreuse3","brown1"), 
         name="RISPOSTE", 
         labels=c("% Risposte Corrette","% Risposte Sbagliate")) + 
     geom_text(aes(1, 
        mediana, 
        label="Assaggiatore Medio", 
        vjust=0), 
       size=4, 
       colour="navy") + 
     scale_y_continuous('% Totale Assaggi')) 

這裏DATA4

SCELTA ASSAGGIATORE Freq  Mediana 
no  Manera   28.57143 63.33333 
si  Manera   71.42857 63.33333 

的例子,我覺得我得到了解決:

ggplot(subset(data4,ASSAGGIATORE=="Manera"), 
    aes(ASSAGGIATORE,Freq,fill=SCELTA),label=Freq)+geom_bar()+ 
     stat_bin(geom="text", aes(position='stack', label=Freq,)) 
+0

我們可以訪問'data4'嗎? – Arun 2013-05-10 14:11:08

+2

當使用'ggplot'時沒有任何理由使用'with',因爲這裏面有一個隱含的'with'。我建議擺脫一堆格式和額外的geoms,並從最基本的開始重現問題的情節。最後,請提供數據,以便我們重現您的問題。 – Justin 2013-05-10 14:21:07

+0

謝謝賈斯汀。我也嘗試過另一種解決方案! – Spigonico 2013-05-10 14:33:48

回答

1
ggplot(subset(data4,ASSAGGIATORE=="Manera"), 
    aes(ASSAGGIATORE,Freq,fill=SCELTA),label=Freq)+geom_bar()+ 
    stat_bin(geom="text", aes(position='stack', label=Freq,)) 

enter image description here