【发布时间】:2021-05-08 06:08:09
【问题描述】:
我有一个数据集,其中包含按年龄(X 轴)递减的 HR 值(Y 轴),分为两组。
https://www.dropbox.com/s/l2p24llxcvndljl/reproducible_data_for_log2plot.txt?dl=0
我正在尝试创建两个 geom_smooth(method = "loess"),Y 轴 (HR) 采用 log2 比例,间距不均匀,受限于从 1 到 70 的指定中断。
读取数据:
aLotOfHRs <- read.table("https://www.dropbox.com/s/l2p24llxcvndljl/reproducible_data_for_log2plot.txt?dl=1" , header = TRUE , sep = "\t")
我的第一次尝试:
p <- ggplot(aLotOfHRs, aes(x = Age,y = HR,fill=Quantiles,color =Quantiles)) +
geom_smooth(method = "loess" , formula = y~x) +
# geom_point() +
theme_minimal() +
ylab("HR per 1-SD (log2 scale)") +
xlim(c(40,72)) +
scale_y_continuous(trans = scales::log2_trans())
不幸的是,比例在视觉上是相等的,但 log2 图是正确的。如果我指定中断、标签和限制:
p <- ggplot(aLotOfHRs, aes(x = Age,y = HR,fill=Quantiles,color =Quantiles)) +
geom_smooth(method = "loess" , formula = y~x) +
# geom_point() +
theme_minimal() +
ylab("HR per 1-SD (log2 scale)") +
xlim(c(40,72)) +
scale_y_continuous(trans = scales::log2_trans()
, breaks = log2(c(1.1,2,4,8,16,32,64))
, labels = c(1.1,2,4,8,16,32,64)
, limits = c(log2(1.1) , log2(70)))
# Note: I can't extend to 1 or it returns
# Error in seq.default(a, b, length.out = n + 1) :'from' must be a finite number
我得到了正确的比例但错误的情节。
迄今为止最好的结果是最后变换坐标,但我仍然无法按照我想要的方式设置中断:
p <- ggplot(aLotOfHRs, aes(x = Age,y = HR,fill=Quantiles,color =Quantiles)) +
# geom_point() +
theme_minimal() +
ylab("HR per 1-SD of PRS (log2 scale)") +
xlim(c(40,70)) +
geom_smooth(method = "loess" , formula = y~x) +
ylim(c(1,70) ) +
coord_trans( y = "log2")
有什么建议吗?
【问题讨论】: