r - R不显示y值但保留y轴
问题描述
这是我在 R 中使用的代码:
library(ggplot2)
df = read.table(sep=",",
header=T,
text="time,bits
1,1
2,1
2,1
2,1
2,1
5,1
5,1
5,1
6,1
6,1
6,1
6,1
6,1
6,1
7,1
7,1
7,1
7,1
7,1
7,1
7,1
7,1")
mapping <- aes(
x = (time)
)
(ggplot(data=df, mapping=mapping)
+ stat_ecdf(geom = "line")
+ geom_vline(xintercept=df$time, linetype="dotted")
+ theme_bw()
+ labs(x = "time t", y = "bits")
+ scale_x_continuous(breaks = c(1,2,5,6,7))
)
我不知道如何从 y 轴上删除值?我发现的大多数帖子根本不显示 y 轴,我只想隐藏这些值。
解决方案
这是一种让线路上升到 ECDF 线路的方法。计算dplyr
管道中的线端。
library(ggplot2)
library(dplyr)
df %>%
mutate(y = cumsum(bits)/sum(bits)) %>%
ggplot(mapping = mapping) +
stat_ecdf(geom = "line", color = "#6400ff", size = 2) +
geom_segment(aes(x = time, xend = time, y = 0, yend = y), linetype="dotted") +
geom_text(
x = 7, y = 1,
hjust = 0.5, vjust = -0.5,
size = 8,
label = expression(italic(R)[1]*(t)),
family = "serif",
inherit.aes = FALSE) +
labs(x = "time", y = "bits") +
scale_x_continuous(breaks = c(1, 2, 5, 6, 7), limits = c(0, 10)) +
ylim(0, 1.5) +
theme_classic() +
theme(
axis.title = element_text(size = 20),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()
)
推荐阅读
- outlook-web-addins - 如何知道 Outlook 插件正在使用 jquery 或 javascript 在浏览器或 Outlook App 中运行?
- python - Python - 将 PyInt 转换为 C int
- java - Java Semaphor 不尊重提供的参数?
- ios - _ContiguousArrayStorage 的 AppDelegate.swift 第 0 行类型元数据访问器
碰撞 - javascript - 小部件的预填充字段
- java - 我的代码中出现意外的 ArraysIndexOutOfBounds 异常
- r - 将对应于同一对值“A”和“B”的数据帧col“C”中的值分配/连接到第二个数据帧。R - dplyr
- python-3.x - 从 Mac 终端多次运行 python 文件
- c# - 如果还需要对象类型参数,如何在字符串类型的函数中传递参数?
- rdlc - 检查 RDLC 中的十进制值为零