首页 > 解决方案 > 如何在 R 中生成带有条形堆栈(不同颜色)的 gap.barplot?

问题描述

我想用堆栈生成 gap.barplot(例如:https ://www.eclipse.org/forums/index.php/t/487795/ )。但是,我不知道怎么做。或者,有没有办法在直方图中进行 y 轴中断?

这是我的数据:

dt <- structure(c(1162L, 699L, 20L, 26L, 2L, 4L, 1L, 11L, 2L, 8L, 5L, 
15L, 2L, 23L, 3L, 25L, 3L, 30L, 0L, 24L, 0L, 23L, 1L, 14L, 0L, 
4L, 1L, 1L, 0L, 2L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 
0L), .Dim = c(2L, 21L), .Dimnames = structure(list(c("FALSE", 
"TRUE"), c("0", "2", "4", "6", "8", "10", "12", "14", "16", "18", 
"20", "22", "24", "26", "28", "30", "32", "34", "36", "38", "40"
)), .Names = c("", "")), class = "table")

我尝试使用包“plotrix”,如下所示,但没有成功。

library(plotrix)

# specifying the gap!
from <- 50
to <- 1830

# x axis
n1 <-seq(-1, 41, by=2)
n2 <- seq(0, 40, 2)

# actual plotting, but it does not work!
gap.barplot(dt, gap = c(from, to), xlab = "index", ylab = "number of points", 
ytics=c(10, 20, 30, 40, 1810, 1840, 1860), xaxlab = n2,  col=c("darkblue","red"),
            legend = rownames(dt))

标签: rggplot2plotrix

解决方案


推荐阅读