2012-10-04 63 views
17

我已經創建了三個面板的格子圖。我可以控制軸和刻度標籤的字體大小,但我一直無法弄清楚如何增加條形標籤的字體大小。下面是一個具體的例子:如何在格子圖形中設置條形標籤字體大小R

# See below for the fake data to run this code 
library(lattice) 
barchart(choice ~ yes+no+not.app|group, data=data, 
     stack=TRUE, col=c("green","red","blue"), 
     xlim=c(0,100), layout=c(3,1), 
     scales=list(cex=c(1.4,1.4), alternating=3), 
     xlab=list(label="Percent of Respondents", fontsize=20), 
     main="") 

下面是這段代碼產生的圖。請注意,除條形標籤(「組1」,「組2」,「組3」)之外,所有字體都很好看。我一直在圍繞R-help和Stack Overflow進行釣魚,但一直未能完成這項工作。有誰知道魔法咒語?

enter image description here

data = structure(list(choice = c("Choice 1", "Choice 1", "Choice 1", 
"Choice 2", "Choice 2", "Choice 2", "Choice 3", "Choice 3", "Choice 3", 
"Choice 4", "Choice 4", "Choice 4"), group = c("Group 1", "Group 2", 
"Group 3", "Group 1", "Group 2", "Group 3", "Group 1", "Group 2", 
"Group 3", "Group 1", "Group 2", "Group 3"), yes = c(23.53, 20.47, 
22.94, 16.51, 16.54, 16.51, 9.68, 13.39, 10.4, 24.48, 29.92, 
25.54), no = c(41.37, 37.01, 40.52, 48.39, 40.94, 46.94, 55.22, 
44.09, 53.06, 40.42, 27.56, 37.92), not.app = c(35.1, 42.52, 
36.54, 35.1, 42.52, 36.54, 35.1, 42.52, 36.54, 35.1, 42.52, 36.54 
)), .Names = c("choice", "group", "yes", "no", "not.app"), row.names = c(NA, 
12L), class = "data.frame") 
+0

應該注意的是,在格子中,「面板」是指繪圖區域內部的內容,而「條形」和「標籤」通常位於繪圖區域之外。 –

+0

剛剛看到您的評論並更新了標題和文本。 – eipi10

回答

24

嘗試(於提供一個例子良好的工作)這樣的:

barchart(choice ~ yes+no+not.app|group, data=data, 
    par.strip.text=list(cex=2), 
    stack=TRUE, col=c("green","red","blue"), 
    xlim=c(0,100), layout=c(3,1), 
    scales=list(cex=c(1.4,1.4), alternating=3), 
    xlab=list(label="Percent of Respondents", fontsize=20), 
    main="") 

要了解更多關於如何管理上,有類型:?strip.default還有其他槓桿來扔在strip.custom。另請參閱latticeExtra軟件包,該軟件包可以用useOuterStrips將條帶放在兩側。

+2

啊,魔術字是'strip'。我一直在討論'panel.this','panel.that'的變體,並沒有到達任何地方。謝謝! – eipi10

+0

面板功能處理框內顯示的內容。所以,是的,這個魔術字是「strip」。我承認我花了幾年的時間來學習這個魔術詞。 –

+0

一個小小的評論:雖然我能夠通過'trellis.par.set()'全局指定所有類似的命令(例如'par.ylab.text = list(cex = 0.8)'),但這對' par.strip.text =列表(CEX = 2)'。它必須在plot命令中指定。任何想法,爲什麼是這種情況? – deca

相關問題