【问题标题】:Solving overlapping scales on Y-axis in R plot.解决 R 图中 Y 轴上的重叠比例。
【发布时间】:2016-07-20 12:06:05
【问题描述】:

我在下面绘制这个图表:

使用这些数据-

输入:

structure(list(trap = structure(1:9, .Label = c("12:00-18:00", 
"18:00-20:00", "20:00-22:00", "22:00-24:00", "24:00-02:00", "02:00-04:00", 
"04:00-06:00", "06:00-12:00", "08:00"), class = "factor"), gambiae = c(26L, 
32L, 40L, 45L, 27L, 8L, 14L, 6L, NA), funestus = c(6L, 15L, 11L, 
11L, 0L, 2L, 3L, 4L, NA), bed = c(0, 0, 0.073458921, 0.57100855, 
0.927149125, 0.969466875, 0.794791474, 0.099302825, 0)), .Names = c("trap", 
"gambiae", "funestus", "bed"), row.names = c(NA, -9L), class = "data.frame")

这是我的图表代码:

par(mar = c(6,6,2,5))
with(bedtimes, plot(as.numeric(trap), gambiae, type="l", col="red3", 
                    ylab=expression(italic(p))), 
     ylim=c(0,40))  
par(new = T)
with(bedtimes, plot(as.numeric(trap), bed, type="l", axes=F, xlab="Time", ylab=NA, cex=1.2))
axis(4)
axis(side = 1, las=2, at=1:length(levels(bedtimes$trap)), levels(bedtimes$trap))
mtext(side = 4, line = 3, 'Proportion in bed')
polygon(bedtimes$bed,col=transp("gray"), border = NA)
par(new=T)
with(bedtimes, plot(as.numeric(trap), funestus, type="l", col="blue3", 
                    ylab=expression(italic(p))), 
     ylim=c(0,40))  

红线的最大值是 40,蓝线的最大值是 15。但正如您在图中看到的那样,两个刻度是重叠的。我需要的是从 0-40 绘制 y 轴,并根据此范围绘制线条。

我认为使用 ylim=c(0,40)) 会设置 y 轴范围,但这对我不起作用。我该如何解决这个问题? 谢谢你。

【问题讨论】:

    标签: r plot


    【解决方案1】:

    plot 函数中必须有 ylim 参数。

    with(bedtimes, plot(as.numeric(trap), funestus, type="l", col="blue3", 
                        ylab=expression(italic(p)),ylim=c(0,40)))  
    

    另外,红线的最大值实际上是 45。相应地更改ylim

    【讨论】:

    • 是的,您必须等待至少 10 分钟才能接受答复。
    猜你喜欢
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2020-07-26
    • 2021-01-12
    • 2015-11-26
    • 2022-01-03
    • 2021-12-06
    • 1970-01-01
    相关资源
    最近更新 更多