R 直方图缩减 y 范围

标签 r graph draw histogram bar-chart

我正在尝试使用 r 绘制如下所示的图表,并且想知道是否有办法

1) 省略 y 值的下限范围,但仍然从 0 开始。

2)另外,如何用文本标记直方图中的每个条形而不是数值?

如果有任何帮助,我将不胜感激。谢谢!

enter image description here

最佳答案

评论中值得一读的答案是使用我选择的同一个plotrix::gap.barplot 示例,但我一直在研究那些“波浪线”:

require(plotrix)
twogrp<-c(rnorm(10)+4,rnorm(10)+20)
gap.barplot(twogrp, gap=c(8,16), xlab="Index", ytics=c(3,6,17,20),
                   ylab="Group values", main="Barplot with gap")
polygon(y=c( 7.5+c(-1,1)*.2*rep(1,length(twogrp)+2),  
             8.5+ c(-1,1)*.2*rep(1,length(twogrp)+2) ) ,
        x=c(0,seq_along(twogrp), rep(length(twogrp)+1, 2), # going to the right...
              rev(seq_along(twogrp)) ,0) ,                # and coming back to the left
        col="white", border="white")  # could also try border="lightblue"

enter image description here

plotrix 中还有一个 axis.break 函数,可以为您提供轴上的注释。您可以使用 text 函数作为绘图区域内的标签。

关于R 直方图缩减 y 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29224232/

相关文章:

r - 使用 ggplot2 左对齐 geom_text 图层

javascript - Vis.js:突出显示选定的节点并使其他节点变灰

c - 偏序集分段故障的格(核心转储)

c# - 以 PointF 为圆心绘制圆 c#

c - opengl+glut glutPostRedisplay在哪里?

java - 绘制和 move 形状问题

r - 如何在 Shiny 中使用 purrr 将一个 renderText 应用于多个输出?

r - 用因子列融化 R data.table

c++ - 从 QR 对象获取 R 矩阵

ios - 如何制作通用顶点以便我可以创建具有混合类型的图形(集合)?