在R中的doubleYScale图中隐藏顶部x轴

时间:2018-10-23 18:04:58

标签: r plot lattice

我正在用doubleYScale绘图绘制两个xyplot。我想隐藏顶部的x轴,但是到目前为止,我所做的所有操作都不起作用或隐藏了所有轴。这有可能吗?

library(lattice)
library(latticeExtra)
x<-seq(1:10)
y<-x^2
y2<-x*2

plot1<-xyplot(y~x, col="black", type="l", ylab="Label1", xlab="") 

plot2<-xyplot(y2~x, col="red", type="l", ylab="Label2", xlab="", scales=list(y=list(col="red")))

doubleYScale(plot1, plot2, add.axis=TRUE, add.ylab2 = TRUE, scales=list(x=list(draw=FALSE)))  

update(trellis.last.object(),
par.settings = simpleTheme(col = c("black", "red"), lty=c(1,1)), horizontal=F, scales=list(x=list(draw=T)))

doubleYScale plot

1 个答案:

答案 0 :(得分:1)

从下面的建议解决方案中可以看出,晶格并不是为轻松完成此特定操作而设置的。也就是说,它是完全可定制的,并且通过一些工作,您可以得到想要的东西。在这里,仅需少量内联注释,便是可以完全隐藏顶部轴的代码:

private void Timer_Tick(object sender, EventArgs e)
{
 string date = now.ToShortDateString();
 foreach (var item in result)
  {
    if(item.Date.Trim() == date.Trim() && item.Time.Trim() ==   now.ToString("t").Trim())
  {
    ParentWindow.SnackbarNotification.IsActive = false;
    ParentWindow.SnackbarNotification.Message.Content = $"{item.Title} - {item.Date} - {item.Time}";
    ParentWindow.SnackbarNotification.IsActive = true;
  }
  else
  { 
    ParentWindow.SnackbarNotification.IsActive = false;
  }
}   
}

enter image description here