r - 从 ggplot2 中的 geom_histogram 中删除水平线
问题描述
我想在右侧绘制一个带有一些文本的直方图,但是 x 轴(或者可能是直方图的下部)延伸到文本。我怎样才能删除这条线?
library(tibble)
library(ggplot2)
library(dplyr)
my_label <- "text"
p <- rnorm(10000) %>%
as_tibble(.) %>%
ggplot(., aes(x = value)) +
geom_histogram(color = 'black', fill = 'grey70', bins = 30) +
annotate(geom = 'text', x = 15, y = 1500, label = my_label,
hjust = 1, size = 3, color = "#cc0000") +
theme_void()
解决方案
A quick hack to rid your plot of the x-axis line
rnorm(10000) %>%
as_tibble() -> dat
dat %>%
ggplot(aes(value)) +
geom_histogram(color = 'black', fill = 'grey70') +
annotate(geom = 'text', x = 15, y = 1500, label = my_label,
hjust = 1, size = 3, color = "#cc0000") +
theme_void() +
geom_histogram(data = tibble(value=1:15), color = 'white')
推荐阅读
- javascript - 未捕获的 ReferenceError:在 hesapmakinesi3.html:10 初始化之前无法访问“计算”
- python - 根据条件和列索引位置应用函数
- python - 正则表达式:匹配直到模式的倒数第二个出现
- android - 如何创建android线性布局cornar废话颜色?
- uialertcontroller - 如何捕捉 [Presentation] 在演示过程中尝试在 xxx(来自 xxx)上演示 xxx
- ios - Stripe - 单一方法预构建 UI,STPAPIClient.shared().publishableKey iOS Swift UiKit
- javascript - wordpress 单页/单页显示/隐藏菜单/图像/按钮单击
- python - Python Selenium 使用多线程打开多个浏览器
- audio - 增加 Gstreamer rtpbin 中的同步率
- javascript - 如何在角度 8 中禁用输入下拉列表的自动填充