2012-02-16 25 views

回答

10

我傾向於使用與鏈接到的博客文章中列出的相同的一般策略。

standard.theme()開始,您可以對設置進行調整,直到您擁有最符合自己需求的自定義主題。一旦你有了你喜歡的東西,只要你想使用它,你可以通過參數par.settings來插入它。

library(lattice) 
# Start work on your own black-and-white theme 
myTheme <- standard.theme(col = FALSE) 
myTheme$superpose.symbol$pch <-1:7 

# These are the kinds of commands you can use to explore the list of available 
# settings as well as their current settings. 
names(myTheme) 
myTheme$superpose.symbol 

# Compare the results of your own theme to those produce by lattice's 
# default settings. 
library(gridExtra) 
p1 <- xyplot(Sepal.Length ~ Petal.Length, group= Species, data = iris, 
      main = "lattice's default theme") 
p2 <- xyplot(Sepal.Length ~ Petal.Length, group= Species, data = iris, 
      par.settings = myTheme, 
      main = "My customized theme") 
grid.arrange(p1, p2, ncol=2) 

enter image description here

+0

完美的,教育性的,百科全書式的答案我從它學到的東西比我原先預想的要多,所以我將其標記爲可接受的,只是我實際上會使用由Justin提供的單行解決方案,因爲它是2行。 – 2012-02-17 19:58:15

+0

@AtilaCsordas我沒有解釋,因爲我不知道!喬希的回答是提供信息。在你學習的同時,我還會研究'ggplot2'包。 – Justin 2012-02-17 20:15:58

3

可能有一個更簡單的方法(我不是非常熟悉格子)但:

library(lattice) 
df <- data.frame(x = rnorm(9), y = rnorm(9), z= letters[1:3]) 

xyplot(x~y,data=df,groups=z, 
     par.settings=list(superpose.symbol=list(pch=1:3, 
               col='black'))) 
+0

它正在工作,它是一個單線,謝謝!我選擇接受的其他答案的原因可以在評論中找到。 – 2012-02-17 19:59:20

+1

@AtilaCsordas - 很高興我們的答案幫助。如果你喜歡他們,你也可以(除了接受他們之外)給他們一個upvote,通過點擊答案左邊的向上三角形。 (我只是提到它,因爲我猜你會想知道,你也可以在網站上對其他問題和答案進行投票。)另外,歡迎來到SO! – 2012-02-17 20:10:37

1

這裏是另一種解決方案,基於panel.superpose,你指的是你的問題:

library(lattice) 
xyplot(Sepal.Length ~ Petal.Length, groups = Species, data = iris, 
panel = function(x,y,...){ 
    panel.superpose(x,y,..., pch=list("A","O","X")) 
}) 

產生以下輸出: panel_superpose_example

lattice使用主要變量 (定義主顯示器),調節變量(定義並列在不同面板中的子組)和分組變量(定義面板內重疊的子組)。

公式Sepal.Length〜Petal.Length和分組語句基團=物種指定要繪製的數據,並把它傳遞給panel其控制繪圖。如果groups!= NULL panel.superpose將分配給pch的列表的第i個元素傳遞給groups的第i級。

對於panelpanel.superpose使用...可以避免定義所有函數參數,並且只聲明那些要定製的函數參數。

pars.settings將自定義設置附加到特定對象,而不像lattice.options會影響全局設置。

相關問題