2012-02-16 24 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会影响全局设置。

相关问题