r - 更改使用 stat_function 绘制的线的大小
问题描述
我正在尝试在 R 上的 ggplot2 中绘制一系列函数stat_function
。该函数始终保持不变,但某些参数会根据数据框中的值而变化。我使用了一个 for 循环来绘制函数的每种不同形式。
我想对绘制的线条使用不同的大小,但是无论我如何更改aes
参数,所绘制的线条的大小都stat_function
保持不变。我可以很好地改变图中其他线条的大小。
编码
test_fun <- function(x,d,fstart,fend,h){
mp=mean(c(fstart, fend))
a=h/((mp-fstart)*(mp-fend))
a*(x-fstart)*(x-fend)
}
plot <- ggplot() + xlim(min(gtf.tx$start), max(gtf.tx$end))+ ylim(-pheight/2,pheight/2)
for(i in 1:nrow(rmats_to_plot)){
weight=rmats_to_plot[i,5]*100
start=rmats_to_plot[i,1]
end=rmats_to_plot[i,2]
flip=rmats_to_plot[i,6]
height=rmats_to_plot[i,8]
plot <- plot+stat_function(mapping = aes(size=1),xlim = c(start,end),fun = test_fun,args = list(fstart=start,fend=end, d=flip,h=height))
}
plot <- plot + geom_hline(yintercept = 0,size=7,color='white')+
geom_hline(yintercept=0,alpha=.9, size=1)+geom_segment(data = gtf.tx,aes(x=start,xend=end,y=0, yend=0),size=7)+theme_minimal()
和数据
start end sample_1 sample_2 total_weight flip size height
31.98 32.71 20.5 39 0.1662 -1 0.73 20
33.36 49.86 16.5 27.5 0.1229 -1 16.5 40
12.13 29.21 20.5 39 0.1662 -1 17.08 60
12.13 32.71 28.5 34 0.1746 1 20.58 -20
51.17 79.79 16.5 40 0.1578 1 28.62 -40
12.13 49.86 21.5 46 0.1885 1 37.73 -60
33.36 79.79 4 2.5 0.0182 -1 46.43 80
12.13 79.79 0 2 0.0056 1 67.66 -80
任何帮助,将不胜感激
解决方案
推荐阅读
- eclipse - 在 Eclipse 中握手期间 SSL 握手失败远程主机关闭连接
- sqlite - 在触发器中引用其他表的列?
- javascript - Vee Validate 自定义跨字段规则,比较两个时间字符串
- vb.net - System.Data.OleDb.OleDbException:“标准表达式中的数据类型不匹配。” VB。网
- html - 循环和显示内容时出错
- android - AWS Device Farm 获取可用设备列表
- sql - SQL Server 中的嵌套 while 循环未显示预期结果
- php - 我正在尝试将 MySQLi 代码转换为 PDO 代码,但没有成功
- java - 来自 Java SE 的 JMS 连接
- tsql - How to: Change actual execution method from "row" to "batch" - Azure SQL Server