Controlling axis ticks and axis lines separately on R lattice xyplot

此生再无相见时 提交于 2019-12-04 03:39:02

This is still a bit hacky, but at least you don't have to do any figuring by hand. It uses a combination of par.settings and a custom axis function that takes an argument line.col and temporarily changes the axis line color by a call to trellis.par.set:

EDIT (removed unnecessary changing of trellis settings)

xyplot(y~x,data=my.df, par.settings = list(axis.line = list(col = "transparent")),
  # Pass custom axis function to argument 'axis'
  axis = function(side, line.col = "black", ...) {
    # Only draw axes on the left and bottom
    if(side %in% c("left","bottom")) {
      # Call default axis drawing function
      axis.default(side = side, line.col = "black", ...)
    }
  }
)

At the moment, I chalk up why line.col = "black" is required in the arguments of the custom axis function to magic. My guess is that it has to do with argument matching with the ellipses (...). Perhaps I'll be wiser tomorrow and find the true reason.

This results in:

Kika Tarsi

The easiest thing to do is to use the custom axis function (axis). Just set lwd (line width) to zero and tick marks (lwd.ticks) to something else. It worked like a charm!

plot(NA,NA,type="n",xaxt="n", lwd=linewidth, xlim=c(1,24), xlab="", ylab="",ylim=c(-300,500))
axis(side = 4, tck = .05, **lwd=0, lwd.ticks=1**, line = 0, labels = NA, col= cols_border[1], col.axis = cols_black)
axis(side = 4, lwd = 0, line = -4.5, las = 1, cex.axis=axis_fontsize, col= cols_border[1], col.axis = cols_black)
mtext("Light deviations (lum/sec)",side=4, padj=-2.5, cex=title_fontsize, col="black")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!