2016-03-22 148 views
-1

我正在對課程評估進行圖形分析。 我得到了以下數據:添加第二個沒有對應x數據的y軸

> str(dataJ2) 
'data.frame': 16 obs. of 22 variables: 
... 
$ lk_nummer   : Factor w/ 111 levels "051-0311-00S",..: 19 30 38 47 49 50 51 55 56 59 ... 
$ le_titel   : Factor w/ 111 levels "","Advanced Methods and Strategies in Synthesis",..: 6 99 75 82 84 8 40 39 38 68 ... 
$ anzahl_stud   : int 7 79 1 34 10 20 83 10 4 11 ... 
$ durchschnitt  : num 4.61 5.35 3.5 4.4 4.4 4.33 4.49 4.53 5.38 4.48 ... 
$ standardabweich  : num 0.4 0.54 0 1.02 1.21 0.62 1.17 0.9 0.28 0.68 ... 
... 
$ prozent_best  : num 85.7 97.5 0 70.6 90 80 73.5 90 100 81.8 ... 
... 

使用GGPLOT2我能夠做圖看起來像這樣:

plotJ2 <- ggplot(dataJ2, aes(y=durchschnitt,x=le_titel)) 

plotJ2 + geom_bar(position=position_dodge(), stat="identity", fill = I("chartreuse4")) + 
    scale_y_continuous(limits=c(0,6.6),breaks=seq(from=1, to=6, by=1)) + 
    geom_errorbar(aes(ymin=durchschnitt-standardabweich, ymax=durchschnitt+standardabweich), width=.1) + 
    ggtitle("2. Jahr Bsc Biologie") + 
    ylab("Durchschnitt") + xlab("Fächer") + 
    geom_text(aes(label = durchschnitt, y = 1.8), size = 4, colour="gray85") + 
    geom_text(aes(label = anzahl_stud, y = 0.2), size = 4, colour="grey85") + 
    geom_text(aes(label = prozent_best, y = 6.55), size = 4, colour="chartreuse4", adj=1) + 
    geom_text(aes(label = "%", y = 6.6), size = 4, colour="chartreuse4", adj=0) + 
coord_flip() 

Which looks like this when plotted.

但然而,「 prozent_best「在圖形部分看起來不是很好。 我試圖用多行文字文本facet_wrap從「dataJ2 $ prozent_best」爲灰色圖形部分的右側的第二y軸的標籤,將數據添加,但不能使它工作。

有什麼建議嗎?

有用的翻譯數據註解/描述:

lk_nummer - >講座的數量

le_titel - >講座的名稱

anzahl_stud - >學生人數

durchschnitt - >平均值

prozent_best - > number of s它通過了考試百分比

Fächertudents - >類

+0

使用不同的主題和左對齊? – Axeman

+0

我會做這樣的事情:http://stackoverflow.com/a/17493256/471093 – baptiste

+0

或者,定義更緊的x xlimits,但關閉gtable面板的裁減 – baptiste

回答

0

嘗試:

geom_text(aes(label = paste0(prozent_best,'%'), y = 6.55), 
size = 4, colour="chartreuse4", hjust='right') 

將在 '%' 符號與價值結合成一個字符串。通常我會建議在ggplot調用之外生成標籤向量,但爲此不會添加太多混亂。

此外,您可能想要考慮添加scale_x_continuous(expand=0,limits=c(0,7))。這將消除左側醜陋的灰色條。

可能也嘗試添加theme_bw()因爲你的情節已經如此繁忙,ggplots標準主題背景中的灰色塊使它看起來很糊狀。

相關問題