R 从晶格直方图中添加和删除网格线

R 从晶格直方图中添加和删除网格线,r,lattice,R,Lattice,我有以下代码,用于创建直方图: inst <- data.frame(c(10:27),c(76,97,128,135,137,141,110,94,67,44,39,26,19,12,7,5,2,1)) names(inst) <- c("instSize","noOfInst") library(lattice) trellis.par.set(theme = col.whitebg()) myplot <- xyplot(noOfInst ~ instSize, dat

我有以下代码,用于创建直方图:

inst <- data.frame(c(10:27),c(76,97,128,135,137,141,110,94,67,44,39,26,19,12,7,5,2,1))
names(inst) <- c("instSize","noOfInst")
library(lattice)
trellis.par.set(theme = col.whitebg())

myplot <- xyplot(noOfInst ~ instSize, data = inst, 
             type = c("h", "g"), col = "blue",
             xlab = "Instance Size (Number of Aircraft)",
             ylab = "Number Of Instances",
             scales=list(
               y=list(
                 at=seq(0,150,10),
                 labels=seq(0,150,10) ),
               x=list(
                 at=seq(10,27,1),
                 labels=seq(10,27,1) )
             )
             )
inst
myplot
myplot
?panel.grid
myplot
?panel.grid

myplot谢谢两位。下面是我最后做的,以防将来有其他人也有同样的问题:

myplot <- xyplot(noOfInst ~ instSize, data = inst, 
             type = c("h"), col = "blue",
             xlab = "Instance Size (Number of Aircraft)",
             ylab = "Number Of Instances",
             panel=function(...){
               panel.abline(h=seq(0,150,10),col="grey")
               panel.xyplot(...)
             },
             scales=list(
               y=list(
                 at=seq(0,150,10),
                 labels=seq(0,150,10) ),
               x=list(
                 at=seq(10,27,1),
                 labels=seq(10,27,1) )
             )
             )

myplot谢谢。下面是我最后做的,以防将来有其他人也有同样的问题:

myplot <- xyplot(noOfInst ~ instSize, data = inst, 
             type = c("h"), col = "blue",
             xlab = "Instance Size (Number of Aircraft)",
             ylab = "Number Of Instances",
             panel=function(...){
               panel.abline(h=seq(0,150,10),col="grey")
               panel.xyplot(...)
             },
             scales=list(
               y=list(
                 at=seq(0,150,10),
                 labels=seq(0,150,10) ),
               x=list(
                 at=seq(10,27,1),
                 labels=seq(10,27,1) )
             )
             )

myplot我最初尝试使用
panel.grid
,但无法使其工作。我假设您必须给出行的位置,如
abline
。很高兴看到它是如何工作的。我和你一样假设,并造成了几次失败。即使我将panel.grid设置为接受
(…,
我遇到了同样的问题!我最初尝试使用
panel.grid
但无法使其工作。我假设您必须像
abline
中那样给出行的位置。很高兴看到它是如何工作的。我和您一样假设,并造成了几次失败。即使我将panel.grid设置为接受(…,
我遇到了同样的问题!很好。我没有在类型定义中看到“g”。我编辑了我的答案以使其更正确。很好。我没有在类型定义中看到“g”。我编辑了我的答案以使其更正确。
myplot <- xyplot(noOfInst ~ instSize, data = inst, 
             type = c("h"), col = "blue",
             xlab = "Instance Size (Number of Aircraft)",
             ylab = "Number Of Instances",
             panel=function(...){
               panel.abline(h=seq(0,150,10),col="grey")
               panel.xyplot(...)
             },
             scales=list(
               y=list(
                 at=seq(0,150,10),
                 labels=seq(0,150,10) ),
               x=list(
                 at=seq(10,27,1),
                 labels=seq(10,27,1) )
             )
             )