首页 > 解决方案 > ggplot2没有显示所有行

问题描述

我们正在研究一些 ggplot2 图表。每个图表包含多条线。但是,当我们的行数超过 3 行时,图表中只显示了 3 行,其余的行都没有了。奇怪的是,传说都在那里。

在此处输入图像描述

这是代码的快照:

     tailStretchPlot[[i]] <- ggplot() +
        geom_step(data=tmp, aes(x=SizeCumPercent-SizeCntPercent/2,
        y=TailStretch, width=SizeCntPercent, colour=TransportType), size=4)

    plotTitle <- paste(append(unlist(strsplit(plotTitle, split='')), '\n',
        as.integer(nchar(plotTitle)/2)), sep='', collapse='')

    xIntervals <- findInterval(c(0)+seq(2,102,10),
        tmp[tmp$TransportType=='homa',]$SizeCumPercent)

    tailStretchPlot[[i]] <- tailStretchPlot[[i]] +
        theme(text = element_text(size=1.5*textSize),
            axis.text = element_text(size=1.3*textSize),
            axis.text.x = element_text(angle=75, vjust=0.5),
            strip.text = element_text(size = textSize),
            plot.title = element_text(size = 1.2*titleSize,
            color='darkblue'), plot.margin=unit(c(2,2,2.5,2.2),"cm"),
            legend.position = c(0.1, 0.85),
            legend.text = element_text(size=1.5*textSize)) +
        guides(colour = guide_legend(override.aes = list(size=textSize/4)))+
        scale_x_continuous(limits = c(0,101),
            breaks = tmp[xIntervals,]$SizeCumPercent,
            labels=tmp[xIntervals,]$MsgSizeRange, expand = c(0, 0)) +
        scale_y_log10(breaks=c(1,2,3,4,5,10,15)) +
        coord_cartesian(ylim=c(1, yLimit)) +
        labs(title = plotTitle, y = yLab, x = xLab)

GitHub 链接是完整的脚本和示例数据 txt 文件:

https://github.com/Stanley131/ggplot2_issue

提前致谢:)

标签: rggplot2

解决方案


推荐阅读