对齐R中的网格线,bReeze包

时间:2016-06-23 14:31:17

标签: r plot gridlines

我正在尝试让网格线在下图中正常工作。使用bReeze包绘制涡轮机的功率曲线:

library(bReeze)
pc=pc("Vestas_V90_1.8MW.wtg") 
plot(pc)

输出图是:

Output Vestas v90 power curve

但在以下情况下将网格线分配给绘图:

grid()

给出下图:

Output with grid lines

有关如何修复扭曲网格线的任何建议吗?

1 个答案:

答案 0 :(得分:1)

如果你不提出一些论点(例如,mar,xlim,ylim), plot(pc)使用par(mar = c(5, 5, 1, 5)并将data.ranges视为xlimylim。通过使用这些属性,您可以使用grid()

pc.data = pc("Vestas_V90_1.8MW.wtg")
plot(pc.data)
par(mar = c(5, 5, 1, 5), new=T)                           # set par() and order to overlay
plot(pc.data[[1]], pc.data[[2]], type="n", ann=F, axes=F) # nothing but setting xy-cordinates
grid(NULL)                                     # here, the same xy-coordinates are reproduced

# If you want to adjust grid lines to right y-axis, use berow code
:
par(mar = c(5, 5, 1, 5), new=T)                   # plot(pc) uses right ylim=c(0,1)
plot(pc.data[[1]], pc.data[[2]], ylim=c(0,1), type="n", ann=F, axes=F)
grid(NULL)                                        # the xy(right)-coordinates are reproduced

# If you plot pc.object having single y-axis, use mar = c(5, 5, 1, 1)

enter image description here